a. While inspecting with Firebug it is getting disappeared.
b. Right click on top of the error message doesn't work to inspect the element in DOM structure.
The Selenium API doesn't support directly a required field. However, you can easily get the state and the message with a piece of JavaScript (Java):
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement field = driver.findElement(By.name("email"));
Boolean is_valid = (Boolean)js.executeScript("return arguments[0].checkValidity();", field);
String message = (String)js.executeScript("return arguments[0].validationMessage;", field);
Note that it's also possible to use getAttribute
to get the validationMessage
even though it's a property:
String message = driver.findElement(By.name("email")).getAttribute("validationMessage");
In Python:
self.browser.get(self.live_server_url + registration_path)
email_input = self.browser.find_element_by_id('id_email_input')
validation_message = email_input.get_attribute("validationMessage");
http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.remote.webelement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With