Hi please find the solution to above problem
package com.daythree;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ExpediaProblem {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "F:\\workspace\\...\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.navigate().to("https://www.expedia.co.in/Flights");
driver.findElement(By.id("flight-origin")).click();
// Thread.sleep(3000);
driver.findElement(By.id("flight-origin")).sendKeys("las");
// wait for the suggestions to appear
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@role='listbox']/div/li/a/div/div"))));
List<WebElement> suggestions = driver.findElements(By.xpath("//*[@role='listbox']/div/li/a/div/div"));
System.out.println("Size of the suggestions is : " + suggestions);
String val = "Las Vegas, NV, US";
for(int i=0;i<suggestions.size();i++){
// this will print all the suggestions
System.out.println("value is : " + suggestions.get(i).getText());
// now logic to select the option
if(suggestions.get(i).getText().contains(val)){
suggestions.get(i).click();
break;
}
}
}
}