我正在尝试在 Lufthamsa Airwyas 站点 URL - http://www.lufthansa.com/online/portal/lh/ua/homepage中自动化 SearchFlights UseCase 。单击“发件人”链接后,将打开一个弹出窗口,我们必须从下拉列表中选择始发国家,根据国家/地区 vaklue,将加载城市下拉列表,选择城市后,将在第三个下拉列表中填充相应的机场。然后必须将焦点转移到主窗口并单击 To 链接,这再次导致相同的弹出窗口(目的地县>>城市>>机场具有相同的下拉菜单)。这是我得到错误的地方。似乎 WbDriver 再次切换到相同的弹出窗口,但它无法在页面上找到元素。和第一次一样,这真的很令人沮丧。我的代码如下 -
公共类 SearchFlights {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.lufthansa.com/online/portal/lh/ua/homepage");
Thread.sleep(3000L);
String main_window = driver.getWindowHandle();
System.out.println("Main Window Handle: "+driver.getWindowHandle());
Thread.sleep(3000L);
driver.findElement(By.xpath("//a[@href='#']/span[@class='airport-dir']")).click();
Thread.sleep(3000L);
for(String sub1_window : driver.getWindowHandles()){
driver.switchTo().window(sub1_window);
driver.findElement(By.xpath("//div[@class='cl first']/ul[@class='aa-select aa- country']/li[@data-value='IN']")).click();
Thread.sleep(2000L);
driver.findElement(By.xpath("//div[@class='cl']/ul[@class='aa-select aa-city']/li[@data-value='DEL']")).click();
Thread.sleep(2000L);
driver.findElement(By.xpath("//div[@class='cl last']/ul[@class='aa-select aa-airport']/li[@data-value='DEL']")).click();
Thread.sleep(2000L);
driver.switchTo().window(main_window);
Thread.sleep(2000L);
driver.findElement(By.xpath("//a[@href='#'][@id ='aa-destination']/span[@class='airport-dir']")).click();
Thread.sleep(2000L);
driver.switchTo().window(sub1_window);
Thread.sleep(3000L);
System.out.println("Sub Window2 Handle: ");
driver.findElement(By.xpath("//div[@class='cl first']/ul[@class='aa-select aa-country']/li[@data-value='HK']")).click();
Thread.sleep(3000L);
driver.findElement(By.xpath("//div[@class='cl']/ul[@class='aa-select aa-city']/li[@data-value='IEV']")).click();
Thread.sleep(3000L);
//driver.findElement(By.xpath("//a[@title='Select'][@href='#']/span")).click();
driver.findElement(By.xpath("//div[@class='cl last']/ul[@class='aa-select aa-airport']/li[@data-value='KBP']")).click();
Thread.sleep(3000L);*/
}
driver.switchTo().window(main_window);*/
}