I have this website https://www.ultimateqa.com/complicated-page/
In it there is a field 'get latest blog posts' I would like to automate the error message, however when I add an invalid email address i.e test123.com a error response is returned but the path to it isn't displayed in the developer options so I can't create a script and verify it.
I can see the validation message in the properties but I can't find a path for it there.
Any help would be most appreciated.
The popup which you are referring is the outcome of Constraint API's [https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Controlling_the_text_of_constraints_violation] element.setCustomValidity() method.
You can use the "validationMessage" attribute like this:
driver.get("https://www.ultimateqa.com/complicated-page/");
WebElement inputElement = driver.findElement(By.xpath("//*[@id=\"subscribe-field-blog_subscription-2\"]"));
System.out.println(inputElement.getAttribute("validationMessage"));
inputElement.sendKeys("test");
System.out.println(inputElement.getAttribute("validationMessage"));
inputElement.sendKeys("[email protected]");
System.out.println(inputElement.getAttribute("validationMessage"));
driver.quit();
Output:
Please fill out this field.
Please include an '@' in the email address. 'test' is missing an '@'.
Last print is empty which is a good email