title: selenium for Google search
body: <p>I am trying to build a simple function in selenium that given a text brings back all the result from Google. I'm using xpath to find all result elements. Although "//a[@class='l']" works as a legit xpath with firebug the resulting list is empty when I run the code. </p>
  
  <pre><code>public void testSearch() {
      WebDriver driver = new FirefoxDriver();
      driver.get("http://www.google.com");
  
      WebElement query = driver.findElement(By.name("q"));
      query.sendKeys("obama twitter");
      query.submit();
  
      long end = System.currentTimeMillis() + 5000;
      while (System.currentTimeMillis() &lt; end) {
          WebElement resultsDiv = driver.findElement(By.className("gssb_e"));
  
          if (resultsDiv.isDisplayed()) {
              break;
          }
      }
  
      List&lt;WebElement&gt; weblinks = driver.findElements(By.xpath("//a[@class='l']"));
      for (WebElement suggestion : weblinks) {
          System.out.println(suggestion.getText()+"\n");
          System.out.println("==&gt; "+suggestion.getAttribute("href")+"\n");
      }
  }
  </code></pre>