title: How to select a text from the autocomplete textbox using selenium
body: <p>I need to enter some text in a autocomplete textbox.
  Then I will select a option from that autocomplete option and need to click it.</p>
  
  <p>I have tried with the following code:</p>
  
  <pre><code>public static void main(String[] args) throws InterruptedException {
      // TODO Auto-generated method stub
      String textToSelect = "headlines today";
  
      WebDriver driver = new FirefoxDriver();
      driver.get("https://www.google.co.in/");
      Thread.sleep(2000);
      WebElement autoOptions= driver.findElement(By.id("lst-ib"));
      autoOptions.sendKeys("he");
  
      List&lt;WebElement&gt; optionsToSelect = driver.findElements(By.tagName("li"));
  
      for(WebElement option : optionsToSelect){
          System.out.println(option);
          if(option.getText().equals(textToSelect)) {
              System.out.println("Trying to select: "+textToSelect);
              option.click();
              break;
          }
      }
  </code></pre>