2017-08-09 18:12

phpwebdriver selenium等待ajax


I using selenium with phpwebdriver, I think so its not phpUnit, anyway I am going to load a page that has ajax load and I want to wait until ajax load compelete, I need to get getPageSource complete.

require_once "phpwebdriver/WebDriver.php";

$webdriver = new WebDriver("localhost", "4444");

$element = $webdriver->getPageSource();
echo ($element);
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • duanliu6083 duanliu6083 3年前

    This is my solution for PHPUnit_Extensions_Selenium2TestCase

     * waitUntil(callback, timeout)
     * callback - will be called in a loop until return non null value or timeout
     * executeAsync(array(string script, array arguments))
     * executeAsync returns arguments of default arguments[0] function when arguments[0] is called.
     * A bit strange, maybe there is another solution to pass the value from browser's js environment.
    protected function waitForAjaxComplete()
        $driver = $this;
        $this->waitUntil(function() use($driver) {
            $condition = 'arguments[0].call(null, $.active == 0)';
                'script' => $condition,
                'args' => array()
                return true;
        }, 10000);

    I'm pretty sure it can be easily converted to the facebook/php-webdriver code

    点赞 评论 复制链接分享