我的問題: 我正在運行phpunit和Selenium來測試位於世界另一端的服務器上的網站。所以,像點擊一個標籤頁或新頁面之類的東西會延遲幾秒鐘。我用Chromedriver啓動Selenium Server。 例如。如何讓Selenium在執行click()命令之前等待頁面完全加載
public function setUp()
{
$this->setHost('localhost'); // Set the hostname for the connection to the Selenium server.
$this->setPort(4444); // set port # for connection to selenium server
$this->setBrowser('chrome'); // set the browser to be used
$this->setBrowserUrl('https://www.*.com'); // set base URL for tests
$this->prepareSession()->currentWindow()->maximize(); // Maximize the window when the test starts
$this->timeouts()->implicitWait(30000); // Wait up to 30 seconds for all elements to appear
}
public function testLoginToeSeaCare(){
$this->timeouts()->implicitWait(10000); // Wait up to 10 seconds for all elements to appear
$url = 'https://www.*.com';
$loginName = 'Ned';
$loginPassword = 'Flanders';
$this->url($url); // Load this url
$this->timeouts()->implicitWait(30000); // Wait up to 30 seconds for all elements to appear
$username = $this->byId('username'); // Search page for input that has an id = 'username' and assign it to $username
$password = $this->byId('password'); // Search page for input that has an id = 'password' and assign it to $password
$this->byId('username')->value($loginName); // Enter the $loginName text in username field
$this->byId('password')->value($loginPassword); // Enter the $loginPassword in password field
$this->byCssSelector('form')->submit(); // submit the form
$tab1Link = $this->byLinkText("Tab1"); // Search for the textlink Tab1
$this->assertEquals('Tab1', $tab1Link->text()); // assert tab text is present
$this->timeouts()->implicitWait(10000); // Wait up to 10 seconds for all elements to appear
$tab2Link = $this->byLinkText("Tab2");
$tab2Link->click(); // Click 'Tab2' tab
}
就有了上面運行,我抓住它在一個XML文件時報告了一個錯誤: ******** :: testSearch PHPUnit_Extensions_Selenium2TestCase_WebDriverException:未知的錯誤:元素...無法點擊在點(430,139)。其他元素將收到點擊:(會話信息:鉻= 57.0.2987.133)(驅動程序信息:chromedriver = 2.29.461591(62ebf098771772160f391d75e589dc567915b233)
我所試圖做的是等待DOM之前完全加載點擊一個按鈕但是我間歇地得到了上面的錯誤有沒有人知道解決這個問題的方法??它驅使我堅果!!
請參閱如何檢查頁面是否已加載-https://sqa.stackexchange.com/questions/26776/how-to-verify-if-a-web-page - 已被正確加載或沒有/ 26786#26786 – demouser123