Selenium Webdriver - verify text box write-protected?
The WebElement
interface has a function called isEnabled.
You can try to write something via sendkeys() and check that value attribute of textbox has not been changed.
- isEnabled() does not have any common things to readonly.
- String attribute = element.getAttribute("readonly"); will not fail your test even "readonly" is absent. In this case it returns null, but we need exception.
Use like this:
WebElement some_element = driver.findElement(By.id("some_id"));
String readonly = some_element.getAttribute("readonly");
Assert.assertNotNull(readonly);
Do NOT verify getAttribute("readonly").equals("true") or similar, in different browsers it can be different as well. (readonly="readonly" in IE, readonly="" in FF, etc.)