Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 636
Karim Narsindani Avatar asked Jan 11 '23 06:01

Karim Narsindani


1 Answers

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....

like image 75
Zach Avatar answered Jan 17 '23 14:01

Zach