Java Selenium WebDriver switchTo().window();IE 8-10超时
在我的应用程序中,单击“搜索”按钮打开几个新窗口。 我需要找到其中一个并切换到它 我用 上面的命令在FF、Chrome、IE11中运行良好,但在IE8-10中使用此命令时会超时。虽然不是所有的时间,超时是随机的,但它们经常发生Java Selenium WebDriver switchTo().window();IE 8-10超时,java,internet-explorer,selenium,selenium-webdriver,webdriver,Java,Internet Explorer,Selenium,Selenium Webdriver,Webdriver,在我的应用程序中,单击“搜索”按钮打开几个新窗口。 我需要找到其中一个并切换到它 我用 上面的命令在FF、Chrome、IE11中运行良好,但在IE8-10中使用此命令时会超时。虽然不是所有的时间,超时是随机的,但它们经常发生 org.openqa.selenium.TimeoutException: Timed out waiting for page to load. (WARNING: The server did not provide any stacktrace informatio
org.openqa.selenium.TimeoutException: Timed out waiting for page to load. (WARNING: The server did not provide any stacktrace information)
我已经对这个问题进行了两天的研究和调试,但找不到解决方法。
这里有一个类似的问题,但对我没有帮助
下面是我的测试用例的一个示例:
public HotelsSearchResultsPage switchToHotelsSearchResultsPage() {
String currentSearchPageWindow = driver.getWindowHandle();
System.out.println("Current - " + currentSearchPageWindow);
Set<String> newOpenedWindows = driver.getWindowHandles();
System.out.println("All - " + newOpenedWindows);
Iterator<String> newOpenedWindow = newOpenedWindows.iterator();
while(newOpenedWindow.hasNext()) {
String popupHandle = newOpenedWindow.next().toString();
if(!popupHandle.contains(currentSearchPageWindow)) {
System.out.println("Switch to - " + popupHandle);
driver.switchTo().window(popupHandle);
if (driver.getTitle().contains("Search Results")) {
log.info("Found and switched to - " + driver.getTitle());
return PageFactory.initElements(driver, HotelsSearchResultsPage.class);
}
}
}
Assert.fail("Could not find 'FareCompare Search Results' page");
return null;
}
如你所见,它只过去了一次。
有什么办法让它工作吗?
感谢过去,我发现当切换窗口出现任何问题时,使用JavascriptExecutor切换窗口是一种可以使用的解决方法。我相信您已经注意到,当您访问IE中的某些页面时,有时加载微调器会在那里停留很长时间。现在的问题是,Selenium在浏览器加载时不与浏览器通信,它只是等待(等待一段时间,然后抛出所提到的异常)。您可以尝试用Robot或类似工具按下停止按钮,但我要做的是完全停止,然后再试一次。@skandigraun谢谢您的回复。不幸的是,我不能重置IE,我使用SauceLabs虚拟机。当我尝试大量地执行相同的步骤时,IE需要5-10秒来加载所有页面,所以看起来这不是一个问题。你能告诉我切换窗口的JavascriptExecutor命令吗?谢谢你能找到方法吗?我有一个类似的问题。刚刚放弃了IE8-10测试。
public HotelsSearchResultsPage switchToHotelsSearchResultsPage() {
String currentSearchPageWindow = driver.getWindowHandle();
System.out.println("Current - " + currentSearchPageWindow);
Set<String> newOpenedWindows = driver.getWindowHandles();
System.out.println("All - " + newOpenedWindows);
Iterator<String> newOpenedWindow = newOpenedWindows.iterator();
while(newOpenedWindow.hasNext()) {
String popupHandle = newOpenedWindow.next().toString();
if(!popupHandle.contains(currentSearchPageWindow)) {
System.out.println("Switch to - " + popupHandle);
driver.switchTo().window(popupHandle);
if (driver.getTitle().contains("Search Results")) {
log.info("Found and switched to - " + driver.getTitle());
return PageFactory.initElements(driver, HotelsSearchResultsPage.class);
}
}
}
Assert.fail("Could not find 'FareCompare Search Results' page");
return null;
}
Run1:
2015-05-22 13:19:59,387 INFO [class] Pushed 'Find Flights' button
Current - ba03b2c7-fe50-41f5-9109-6e68da460432
All - [12a3fe77-9181-4385-9682-d90733294f9f, 5c2c879e-5077-46b6-bfd6-323aea85c61d, ba03b2c7-fe50-41f5-9109-6e68da460432, 965c2650-c8d7-4262-bd79-c34bac78d163]
Switch to - 12a3fe77-9181-4385-9682-d90733294f9f
2015-05-22 13:20:14,561 INFO [class] Found and switched to - IEV LAX Flight Search Results - FareCompare
Run2:
2015-05-22 13:22:39,342 INFO [class] Pushed 'Find Flights' button
Current - 670bb987-c671-4e0f-9e0b-1f128154f567
All - [670bb987-c671-4e0f-9e0b-1f128154f567, 3428b6ba-a9b3-4480-9c82-ff75ecd3cbcd, 3d7c3894-8c1a-417b-a9f8-b9ba7f402331, a48e6b53-2f5a-4f19-a23f-3a7a705491fe]
Switch to - 3428b6ba-a9b3-4480-9c82-ff75ecd3cbcd
Switch to - 3d7c3894-8c1a-417b-a9f8-b9ba7f402331
2015-05-22 13:23:46,937 INFO [class] *** FAILURE
Run3:
2015-05-22 13:25:05,120 INFO [class] Pushed 'Find Flights' button
Current - 46028415-e337-4dbb-91bf-4cbfc71c98fe
All - [994e517c-0ac1-428c-8596-6aa2b0c3f9f0, 46028415-e337-4dbb-91bf-4cbfc71c98fe, 0b2b5867-012a-4b6e-9539-96258e18ce3b, 84905382-4d17-41af-9346-5a4fe444b4f9]
Switch to - 994e517c-0ac1-428c-8596-6aa2b0c3f9f0
Switch to - 0b2b5867-012a-4b6e-9539-96258e18ce3b
2015-05-22 13:26:16,501 INFO [class] *** FAILURE
Run4:
2015-05-22 13:13:30,109 INFO [class] Pushed 'Find Flights' button
Current - 142dd89b-99a8-4aa7-8e05-cb0377d72d24
All - [dd7935e7-e70f-48b6-8d9e-dd3185b02efa, 142dd89b-99a8-4aa7-8e05-cb0377d72d24, 0515e9e6-3a07-4edc-8008-5330d01f363e, 379ccfde-2c2b-45d8-bc5b-4f9638ec665d]
Switch to - dd7935e7-e70f-48b6-8d9e-dd3185b02efa
2015-05-22 13:14:36,543 INFO [class] *** FAILURE