0

I am using this code to verify if error message is present in page.

field_required = driver.findElements(
    By.xpath("//*[@id='tab1']/fieldset/div/div/*[text()='This field is required']")
);

and checking if field_required.size() > 0

The error message should appear only if I leave a field blank and click submit. I noticed that even before I click submit field_required.size() is greater than zero .

Hence am guessing that my validation is not done by this code. Please give me another way that would work. Not sure why I am getting incorrect results here.

1
  • Check if your field validations is done by javascript with the onblur event. Commented Sep 14, 2016 at 6:50

1 Answer 1

1

Seems like element is already present in the DOM and invisible to end user.

Would you please modify your code as below and try?

field_required.size() && field_required.isDisplayed()

Here is the link for isDisplayed method

Sign up to request clarification or add additional context in comments.

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.