Selenium RC WaitForPageToLoad Hangs

心已入冬 提交于 2019-12-04 20:23:56

The example in the Selenium RC documentation is obsolete. Google changed the way their home page worked quite a while ago, and it is no longer a simple HTML page. Pressing the search button is now an AJAX-type operation that sends the search request and gets back a JSON response that is processed by the JavaScript code in the page. So the page never is re-loaded, and WaitForPageToLoad() eventually times out.

There is also another possible cause of this situation that I ran into just now. According to the documentation, if you call ANY SELENIUM COMMANDS in between loading a page and calling waitForPageToLoad, then it is possible that waitForPageToLoad will hang. (If I understand it correctly, it is technically a race condition between the test script and selenium server, so it happens sometimes, not necessarily all the time).

In most cases, the page load is caused by a click event. When you have a test script like:

$this->click("/some/path");
//  <<- NO SELENIUM COMMANDS HERE
$this->waitForPageToLoad("30000");

Make extra sure that no selenium commands ever accidentally get inserted into the marked area.

While this is not technically the same problem that the OP posted about, it has the same error message, and I couldn't find this information without digging around quite a bit. Hopefully this is easier to find for other people in the future.

I have observed same problem many times. Hence I did not use this command when user is not navigating away from current page. It hangs at times and using IsElementPresent in while loop and exit after it return true.

An alernative to "WaitForPageToLoad()" Is to wait for an element to be present.


    $SECONDS = 360;

for ($second = 0; ; $second++) {
    if ($second >= $SECONDS) $this->fail("TIMEOUT");
    try {
        if ($this->isElementPresent("edit-submit")) break;
    } catch (Exception $e) {}

    sleep(1);
}

This code will loop for 360 seconds, checking if the value (edit-submit) is present each second. ("sleep(1)"). It essentially will achieve the same result as WaitForPageToLoad, but you can specify an absolute target.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!