簡體   English   中英

Selenium WebDriver switchTo()。window(); IE 8-10超時

[英]Selenium WebDriver switchTo().window(); IE 8-10 timeout

在我的應用程序中,單擊“搜索”按鈕會打開幾個新窗口。 我需要找到其中之一並切換到該位置。

我用

driver.switchTo().window(popupHandle);

上面的命令在FF,Chrome,IE11中工作正常,但是在IE8-10中使用此命令時出現超時。 並非總是如此,超時是隨機的,但它們經常發生。

org.openqa.selenium.TimeoutException: Timed out waiting for page to load. (WARNING: The server did not provide any stacktrace information)

我已經在研究和調試此問題兩天了,但是找不到解決方法。 這是一個類似的問題,但並沒有幫助我“ IE中的硒WebDriver切換問題”

這是我的測試用例的示例:

  1. 轉到此頁
  2. 填寫城市,日期和最少3個(或所有少於3個)網站進行比較
  3. 點擊“搜索”

在某些測試案例中,我需要切換到結果頁面,在其他情況下切換到每個頁面並獲得標題。

這是我的代碼示例:

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

如您所見,它僅通過了一次。 有什么想法使它起作用嗎? 謝謝

過去,我發現在切換窗口時遇到任何問題時,可以使用JavascriptExecutor來切換窗口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM