2017-08-09 119 views
0

我用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); 

回答

0

這是我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的代碼

+0

好男人,這似乎是你所熟悉的硒,請你看看這個報價:https://stackoverflow.com/questions/48222301/next-click-seleum-gets-broken – kiamoz

+0

其實我很新。只是與其他人共同開發的共享解決方案,導致此擴展的文檔非常有用。 –