RE: HTML 5 provide “required” attribute. For Email field, It give different message based on email entered. I want to check these message using Selenium webdriver, Please Help.

1 Answers

Hi Anand,

This is a good question, however there is no way right now that you can read HTML 5 error messages. The reason is that the error message is not part of the DOM and is also generated by the browser. Every browser will have different implementations for it.

All you can validate is that whether the element is in error state or not. You can find the current element which is in error state by using following command

WebElement invalidInput = driver.findElement(By.cssSelector(“input:invalid”));

Just verifying that this is indeed the element that should have thrown error should be enough to tests.

Error message that you get is from browser and you cant do much about what error message browser chooses to display.


Professor Answered on June 3, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.