我的问题: 我正在运行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