How to find input field is readonly or not in using selenium webdriver with java

java, javascript, selenium-webdriver

Solution

You can achieve this without having to execute JS, all you need to do is to get the DOM Attribute of the element which is "ReadOnly" this can be achieved using:

   WebElement readOnly = driver.findElementBy(locator);
   Assert.assertTrue(readOnly.getAttribute("readOnly").equals("true"),"Element ReadOnly")

Hope this helps....

Problem

I am using selenium webdriver with java to write the script. However, we have few fields which are getting disabled after click on button. We need to find this field are getting readonly mode or not. I have use `isEnabled` and `isDisplayed` but it is not working, the system displays `NoSuchElementFound` expection. Is there any way to handle this?

Original source