MinkPhantomJSDriver
MinkPhantomJSDriver copied to clipboard
document.readyState never changes
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.
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".
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.
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.
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.