title: Unable to capture error message - selenium java junit
body: <p>I need to capture the error messages displayed, i tried many methods but every method throws exception --unable to find element,
  pls help with the code. These are the methods i tried.Also, there is no ID, it is div element. something like this...</p>
  
  <pre><code>&lt;div id="webformErrors" class="text" name="errorContent"&gt;
  &lt;div&gt;
  There were 4 errors:
  &lt;ul&gt;
  &lt;li&gt;
  You did not enter a value for:
  &lt;b&gt;First Name&lt;/b&gt;
  &lt;/li&gt;
  &lt;li&gt;
  You did not enter a value for:
  &lt;b&gt;Last Name&lt;/b&gt;
  &lt;/li&gt;
  &lt;li&gt;
  &lt;li&gt;
  
  //String errormsg;
  ![enter image description here][1]errormsg = Hcd.findElement(By.xpath("//div[@id=webformErrors']/text()")).getText();
  
  // WebElement divElement = Hcd.findElement(By.className("errorContent"));
  
  // Hcd.findElement(By.name("There were 4 errors:")).isDisplayed();
  
  **String pstring = Hcd.findElement(By.id("webformErrors")).getText();
          System.out.println(pstring);
  </code></pre>