title: Clicking autocomplete menu item using Selenium
body: <p>I am trying to test the auto complete feature in a search wizard wherein after sending search query, I have to click on the top menu item which would appear as auto complete just like it happens in Google search.</p>
  
  <p>Below is the html structure that appears when I type <code>Text</code> in search bar:</p>
  
  <pre><code>&lt;ul class="ui-autocomplete ui-autocomplete-icons ui-menu ui-widget ui-widget-content ui-corner-all" role="listbox"&gt;
  &lt;li class="ui-menu-item" role="menuitem"&gt;
      &lt;a class="partition_item ui-corner-all" tabindex="-1"&gt;
          &lt;i class="autocomplete_icons autocomplete_city"&gt;&lt;/i&gt;
          &lt;span&gt;&lt;b&gt;Text A&lt;/b&gt;&lt;/span&gt;
      &lt;/a&gt;
  &lt;/li&gt;
  
  
  &lt;li class="ui-menu-item" role="menuitem"&gt;
      &lt;a class="partition_item ui-corner-all" tabindex="-1"&gt;
          &lt;i class="autocomplete_icons autocomplete_city"&gt;&lt;/i&gt;
          &lt;span&gt;&lt;b&gt;Text B&lt;/b&gt;&lt;/span&gt;
      &lt;/a&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p></p>
  
  <p>I need to click the first menu item in auto complete which is <code>Text A</code> here in this case.
  Below is what I have tried in java:</p>
  
  <pre><code>destinationInput.sendKeys(city);
      try {
          Thread.sleep(3000);
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      WebDriverWait wait = new WebDriverWait(driver, 5);
      wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("ul.ui-autocomplete")));
      List &lt;WebElement&gt; listItems = driver.findElements(By.className("partition_item"));
      listItems.get(0).click();
  </code></pre>
  
  <p>But nothing seems to happen. I am getting <code>IndexOutOfBoundException</code> at <code>listItems.get(0)</code> which i guess is because its unable to get the anchor tags inside ul element.</p>
  
  <p>I also had gone through <a href="https://stackoverflow.com/a/13459501/1471314">this answer</a> but am unable to incorporate it in java. Please guide.</p>