title: Why doesn't Selenium find element by xpath?
body: <p>When I run the following program, why is '0' printed to the console? I expected '1' to be printed since I expected the <code>findElements()</code> method to find a link using the xpath. Is the xpath expression incorrect? I got the expression using Firefox, Firebug, and Firepath, by selecting the link element and copying the given xpath.</p>
  
  <pre><code>import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.By;
  import java.util.List;
  
  public class SeleniumSearch {
      static WebDriver driver = new FirefoxDriver();
  
      public static void main(String[] args) {
  
          try {
              driver.get("http://www.google.co.uk/");
              submitSearch("selenium");
              getHit();
          }
          finally {
              driver.close();
          }
      }
  
      static void submitSearch(String search) {
          WebElement searchBox = driver.findElement(By.name("q"));
          searchBox.sendKeys(search);
          searchBox.submit();
      }
  
      static void getHit() {
          List&lt;WebElement&gt; hits = driver.findElements(By.xpath("html/body/div[5]/div[4]/div[9]/div[1]/div[3]/div/div[3]/div[2]/div/div/div/div[2]/div[1]/div/h3/a"));
          System.out.println(hits.size());
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/KuBRD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KuBRD.png" alt="Screen shot of the xpath given by Firepath"></a></p>