title: Assert that a WebElement is not present using Selenium WebDriver with java
body: <p>In tests that I write, if I want to assert a WebElement is present on the page, I can do a simple:</p>
  
  <pre><code>driver.findElement(By.linkText("Test Search"));
  </code></pre>
  
  <p>This will pass if it exists and it will bomb out if it does not exist.  But now I want to assert that a link does <em>not</em> exist.  I am unclear how to do this since the code above does not return a boolean.</p>
  
  <p><em>EDIT</em> This is how I came up with my own fix, I'm wondering if there's a better way out there still.</p>
  
  <pre><code>public static void assertLinkNotPresent (WebDriver driver, String text) throws Exception {
  List&lt;WebElement&gt; bob = driver.findElements(By.linkText(text));
    if (bob.isEmpty() == false) {
      throw new Exception (text + " (Link is present)");
    }
  }
  </code></pre>