2

I test web application that uses HTML5 Constraint Validation API to generate error pop-ups. How to verify text in the pop-ups in selenium tests? I cannot find the appropriate locators.

4
  • 1
    can you plz show us the source code of your app and what you have done Commented May 25, 2016 at 9:18
  • 1
    you don't need my source code. I asked how to verify text in these messages: sagarganatra.com/2011/07/… Commented May 25, 2016 at 9:20
  • 1
    i think this is the source code <form id="myForm"> <input id="eid" name="email_field" type="email" /> <input type="submit" /> </form> Commented May 25, 2016 at 9:33
  • in ur website the messages are in image. From image u can't get the text. Commented May 25, 2016 at 10:17

2 Answers 2

2

The Selenium API doesn't support directly the constraint validation. However, you could 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 is also possible to use getAttribute to get the validationMessage even though it is a property:

String message = driver.findElement(By.name("email")).getAttribute("validationMessage");
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! I used ....getAttribute("validationMessage") and got the message.
1

as per your link provided sample HTML code snippet that address your problem is :

<form id="myForm">
<input id="eid" name="email_field" type="email" />
<input type="submit" />
</form>

i have gone through above html source and looked it very clearly ,but there is no html source code in the source code for validation message that generates after clicking on "Submit query".

However i can guide you throw a workaround that will work as good as if had worked when you have the error message.

Please understand that this way:

1.Please observer source code of input boxes with Constraint Validation API in HTML5?
2.you will clearly see that its attribute defines what type of data they can take in 
  our example attribute name and type.
3.they both clearly say that above html code will take input in the form of email only.
4.so your logic will be to check value entered in the input box is of the type of 
  email or not.if its email then pass the test otherwise fail.

Hope this make sense top you and eventually helps you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.