How to locate an error message in the website dev options if the inspector isn't finding it

awalker23 :

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.

Adi Ohana :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=149057&siteId=1