dongyu8694 2017-08-09 18:12
浏览 106
已采纳

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");
$webdriver->connect("firefox");                            
$webdriver->get("http://www.hoopabooks.ir/%DA%A9%D8%AA%D8%A7%D8%A8-%D9%87%D8%A7%DB%8C-%D8%AE%D9%88%D8%B1%D8%AF%D9%86%DB%8C");         

$element = $webdriver->getPageSource();
echo ($element);
  • 写回答

1条回答 默认 最新

  • duanliu6083 2018-01-11 16:25
    关注

    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)';
            if($driver->executeAsync(array(
                'script' => $condition,
                'args' => array()
                ))
            )
                return true;
        }, 10000);
    }
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功