php-webdriver: wait for browser response after submitting form using click() php-webdriver: wait for browser response after submitting form using click() selenium selenium

php-webdriver: wait for browser response after submitting form using click()


php-webdriver from Facebook has been rewritten in June 2013. You can wait for the URL easily like this.

// wait for at most 10 seconds until the URL is 'http://example.com/account'.// check again 500ms after the previous attempt.$driver->wait(10, 500)->until(function ($driver) {  return $driver->getCurrentURL() === 'http://example.com/account';})


Okay, so I know this is a very old question, but as I stumbled upon it through Google I hope that this can still be useful for someone (maybe even the OP? :-)).

After quite some searching and reading articles and messages on Google Code, I found a solution that I think is quite ugly, but there is not really a good alternative. You can read here that it is impossible for WebDriver to detect when the page has loaded. So, we have to revert to waiting. Now, the OP is using Facebook's PHP WebDriver, which does not include waiting utilities AFAIK, but when using this maintained clone, you get an implementation of WebDriverWait.

Now the question is: what do we wait for? You could wait for the URL to change, but this is in no way a reliable approach as the page probably is not loaded yet when the URL has changed already. Next option: wait for an element you know is on the page to be loaded to appear. That'll work, but what if you want to have a more generic approach? Luckily, I read a very good idea in the thread I mentioned above. You can wait for an element that is on both pages to disappear and the reappear, for example the footer.

I implemented this just now and it seems to work. Below function can be passed your $session and will only return when the new page is loaded (or at least, the footer is available again).

public static function waitForNextPage($pWDSession) {    $aWait = new PHPWebDriver_WebDriverWait($pWDSession);    // wait for footer to not be available anymore    $aWait->until(            function($pWDSession) {                return (0 === count($pWDSession->elements(PHPWebDriver_WebDriverBy::CSS_SELECTOR, "#footer,#mx-footer")));            }        );    // wait for footer to be available again    $aWait->until(            function($pWDSession) {                return (0 < count($pWDSession->elements(PHPWebDriver_WebDriverBy::CSS_SELECTOR, "#footer,#mx-footer")));            }        );}

You can obviously change the selector or use some other element, the idea remains the same.

I hope it helps! Cheers!


Instead of click() it should be possible to use clickAndWait(), in order to wait until the next page has been loaded.