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.