PHP webdriver wait for Ajax to finish executing

痴心易碎 提交于 2020-11-29 19:25:14

问题


Simply want to check that ajax is no longer executing, but there's not much in terms of documentation for this.

Closest answer I found is: phpwebdriver selenium wait for ajax

I tried to adapt the code in the answer below:

public function waitForAjaxComplete()
{

    $wait = new WebDriverWait($driver, 30);
    $wait->until(function(){
        $condition = 'arguments[0].call(null, $.active == 0)';
        if($driver->executeAsyncScript(array(
            'script' => $condition,
            'args' => array()
        ))
        )
            return true;
    }, 10000);
}

But it's returning the following:

PHP Fatal error:  Uncaught Facebook\WebDriver\Exception\UnknownServerException: java.util.HashMap cannot be cast to java.lang.String in vendor/facebook/webdriver/lib/Exception/WebDriverException.php:114

I tried variations of $condition, but it keeps returning the same thing. Sure others would find this solution useful as it would help determine when page containers finished reloading with new content via Ajax or simply to be able to confirm when javascript stopped executing on page using php webdriver


回答1:


If you are doing AJAX requests using jQuery, you can use this:

$driver->wait()->until(
    function ($driver) {
        return $driver->executeScript('return jQuery.active === 0;');
    }
);



来源:https://stackoverflow.com/questions/64590437/php-webdriver-wait-for-ajax-to-finish-executing

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