MinkPhantomJSDriver icon indicating copy to clipboard operation
MinkPhantomJSDriver copied to clipboard

document.readyState never changes

Open thedamnedrhino opened this issue 8 years ago • 4 comments

I'm using the following code, to wait for page loads e.g: after clicking links:

    protected function waitForPageLoad(){
        $this->session->wait(10000, '(document.readyState === "loading")');
        $this->session->wait(10000, '(document.readyState === "complete")');
    }

but it looks like document.readyState never changes, (initially I didn't have the first call to wait(), but when it didn't work I added the first line to wait until the new page starts loading). Because the first call to wait always returns false and the second one always true. If I remove the first call to wait() the second call will still always return true, regardless of the page having loaded or not.

thedamnedrhino avatar Sep 16 '16 07:09 thedamnedrhino

Thanks for reporting, I will have to check whether this is an error of phantomjs code in the driver or a bug itself in phantomjs while querying "document.readyState".

jcalderonzumba avatar Sep 19 '16 13:09 jcalderonzumba

Any updates on this issue?
The underlying objective is to detect when the page has finished loading (redirecting) and all ajax requests are completed. Currently I need to place wait($time) calls manually everywhere to account for this. And this will result in some problems because if $time is too big, the tests will take too long. If it's too small, some tests (undeterministically) won't pass because sometimes the waiting time is not enough and e.g the page hasn't loaded yet.

thedamnedrhino avatar Mar 14 '17 08:03 thedamnedrhino

I have been digging and unfortunately the way visit() method works is by calling http://phantomjs.org/api/webpage/method/open.html internally and that function basically waits for the document to be loaded that is why your document.ready never changes because when "visit()" finishes the pages has already been loaded.

jcalderonzumba avatar Mar 17 '17 08:03 jcalderonzumba

Actually there is no problem when I use visit() because the page is correctly loaded. But when I interact with a page and I'm somehow redirected e.g redirection through some JS on the page, then I can't detect when the "new" page has finished loading.

thedamnedrhino avatar Mar 17 '17 09:03 thedamnedrhino