phpwebdriver硒等待ajax
问题描述:
我用phpwebdriver使用硒,我认为它不是phpUnit,无论如何,我要加载一个页面,有一个Ajax加载,我想等到ajax加载完成,我需要getPageSource完成。phpwebdriver硒等待ajax
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);
答
这是我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);
}
解决方案,我敢肯定它可以很容易地转换到了Facebook/PHP-webdriver的代码
好男人,这似乎是你所熟悉的硒,请你看看这个报价:https://*.com/questions/48222301/next-click-seleum-gets-broken – kiamoz
其实我很新。只是与其他人共同开发的共享解决方案,导致此扩展的文档非常有用。 –