【发布时间】:2015-08-13 09:20:30
【问题描述】:
我已经编写了以下代码来打开一个谷歌地图窗口获取它的 url 然后关闭它并在我之前的窗口上执行操作:
try
{
String winHandleBefore = driver.getWindowHandle();
element("icon_google_map").click();
for(String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
Thread.sleep(9000);
String currentURL = driver.getCurrentUrl();
logMessage(currentURL);
String expectedURL="xyz";
Assert.assertEquals(currentURL, expectedURL);
logMessage(currentURL);
driver.close();
driver.switchTo().window(winHandleBefore);
return true;
}
catch(Exception e)
{
return false;
}
上面的代码打开地图窗口但没有关闭它,而是当我在前一个窗口执行操作时显示以下错误。
错误: org.openqa.selenium.NoSuchWindowException:没有这样的窗口:目标窗口已经关闭
【问题讨论】:
标签: java selenium-webdriver window-handles