Test autocomplete with Selenium webdriver

I found a workaround about this. My problem was:

  1. Selenium inputted 'Mandaluyong' to an auto-suggest location field
  2. The auto-suggest field appears together with the matched option
  3. Then selenium left the auto-suggest drop-down open not selecting the matched option.

What I did was:

        driver.findElement(By.name("fromLocation")).sendKeys("Mandaluyong");
        driver.findElement(By.name("fromLocation")).sendKeys(Keys.TAB);

This is because on a manual test, when I try to press TAB key, two things were done by the system:

  1. Picks the matched option from the auto-suggest drop-down
  2. Closes the auto-suggest drop-down