我需要關閉子窗口並切換回父窗口才能執行某些操作。如何使用硒webdriver從父窗口切換到子窗口
public static void nextTab() throws InterruptedException {
Set winSet = UIPage.getBaseWindow().getWindowHandles();
List winList = new ArrayList(winSet);
String newTab = winList.get(winList.size() - 1); UIPage.getBaseWindow().switchTo().window(newTab);
Thread.sleep(Constant.LONG_TIMEOUT_500);
}
public static void prevTab() {
Set winSet = UIPage.getBaseWindow().getWindowHandles();
List winList = new ArrayList(winSet);
UIPage.getBaseWindow().close();
String oldTab = winList.get(winList.size() - 2); //System.out.println(oldTab);
UIPage.getBaseWindow().switchTo().window(oldTab);
}
請格式化源代碼 – dpassy
我想下面鏈接可能對這項有益的。 http://stackoverflow.com/questions/14620253/how-to-switch-control-from-child-window-to-parent-window-in-selenium-webdriver?rq=1 – MamathaMacherla