【发布时间】:2017-09-18 14:44:47
【问题描述】:
我的问题: 我正在使用 Selenium 运行 phpunit 来测试位于世界另一端的服务器上的网站。因此,单击选项卡或新页面等操作会有几秒钟的延迟。我用 Chromedriver 启动 Selenium Server。 例如。
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) 处不可点击。其他元素将收到点击:(会话信息:chrome=57.0.2987.133)(驱动程序信息:chromedriver=2.29.461591(62ebf098771772160f391d75e589dc567915b233)
我要做的是等待 DOM 完全加载,然后再单击按钮。但是我间歇性地收到上述错误。有谁知道解决这个问题的方法??快把我逼疯了!!
【问题讨论】:
-
请查看如何检查页面是否已加载 -sqa.stackexchange.com/questions/26776/…
标签: selenium-webdriver phpunit selenium-chromedriver