Java 如何切换到新的浏览器窗口?

Java 如何切换到新的浏览器窗口?,java,selenium,Java,Selenium,我正在使用selenium实现应用程序的自动化 我正在尝试切换到新的浏览器窗口。但是我的代码卡在了driver.switchTo().window(winhandles)行中 没有任何例外 您可以在以下窗口之间切换: // Store the current window handle String winHandleBefore = driver.getWindowHandle(); // Perform the click operation that opens new window

我正在使用selenium实现应用程序的自动化

我正在尝试切换到新的浏览器窗口。但是我的代码卡在了driver.switchTo().window(winhandles)行中


没有任何例外

您可以在以下窗口之间切换:

// Store the current window handle
String winHandleBefore = driver.getWindowHandle();

// Perform the click operation that opens new window

// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
}

// Perform the actions on new window

// Close the new window, if that window no more required
driver.close();

// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);

// Continue with original browser (first window)

你能提供更多的代码吗,这不能帮助回答吗?你的
窗口(winhandles)
winhandles有什么值?对于(字符串winNames:windowSet){try{mLog.debug(“尝试切换到窗口:+winNames”);driver.switchTo().window(winNames);mLog.debug(切换到:“+driver.getTitle()+”Window…);}catch(NoSuchWindowException ex){tempSet.add(winNames);}}}这是我的代码..windowSet=driver.getWindowHandles();for(String winNames:windowSet){try{mLog.debug(“尝试切换到Window:+winNames”);driver.switch to().window(winNames);mLog.debug(“切换到:“+driver.getTitle()+”window…”);}catch(NoSuchWindowException ex){tempSet.add(winNames);}