title: How to verify error message displayed in page using selenium webdriver-Java
body: <p>I am using this code to verify if error message is present in page.</p>
  
  <pre><code>field_required = driver.findElements(
      By.xpath("//*[@id='tab1']/fieldset/div/div/*[text()='This field is required']")
  );
  </code></pre>
  
  <p>and checking if <code>field_required.size() &gt; 0</code></p>
  
  <p>The error message should appear only if I leave a field blank and click submit. I noticed that even before I click submit <code>field_required.size()</code> is greater than zero . </p>
  
  <p>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.</p>