Select first value from the suggested auto complete list using Selenium WebDriver
import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SelectFirstAutoCompleteValue {
@Test
public void selectFirstAutoCompleteValue() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.aa.com/homePage.do?locale=en_US");
driver.manage().window().maximize();
driver.findElement(By.id("reservationFlightSearchForm.originAirport")).clear();
Thread.sleep(2000);
driver.findElement(By.id("reservationFlightSearchForm.originAirport")).sendKeys("kan");
Thread.sleep(2000);
WebElement we1 = driver.findElement(By.cssSelector("#ui-id-3.ui-autocomplete"));
List<WebElement> list1 = we1.findElements(By.cssSelector(".ui-corner-all"));
Thread.sleep(2000);
list1.get(0).click();
Thread.sleep(2000);
driver.findElement(By.id("reservationFlightSearchForm.destinationAirport")).sendKeys("san");
Thread.sleep(2000);
WebElement we2 = driver.findElement(By.cssSelector("#ui-id-4.ui-autocomplete"));
List<WebElement> list2 = we2.findElements(By.cssSelector(".ui-corner-all"));
Thread.sleep(2000);
list2.get(0).click();
Thread.sleep(2000);
driver.close();
}
}