String mainWindow = driver.getWindowHandle();
driver.findElement(By.xpath(pro.getProperty(""))).click();
for(String newWindow : driver.getWindowHandles()){
driver.switchTo().window(newWindow);
}
driver.close();
Log.info("Closing the current Opened Window - Invoice");
driver.switchTo().window(mainWindow); ---error in this line
切换到主窗口时出错。
org.openqa.selenium.NoSuchWindowException:没有这样的窗口:目标窗口已经因未知错误而关闭:找不到Web视图
我已经尝试切换到默认窗口,注释driver.close并添加thread.sleep但问题未解决。
@ user7309686希望以下脚本能解决您的问题。最好在切换到新窗口之前进行一次验证。谢谢
public void switchToNewWindow(WebDriver driver)
{
String mainWindow = driver.getWindowHandle();
Set<String> openedWindows = driver.getWindowHandles();
if(openedWindows.size() > 1)
{
for(String newWindow : openedWindows)
{
driver.switchTo().window(newWindow);
}
driver.close();
Log.info("Closing the current Opened Window - Invoice");
driver.switchTo().window(mainWindow);
}
}