Selenium webdriver 如何让Selenium在执行click()命令之前等待页面完全加载

Selenium webdriver 如何让Selenium在执行click()命令之前等待页面完全加载,selenium-webdriver,phpunit,selenium-chromedriver,Selenium Webdriver,Phpunit,Selenium Chromedriver,我的问题是: 我正在使用Selenium运行phpunit,以便在世界另一端的服务器上测试一个网站。因此,单击选项卡或新页面等操作会延迟几秒钟。我用Chromedriver启动Selenium服务器。 例如 运行上述操作时报告了一个错误,我将其捕获到一个xml文件中: ********::testSearch PHPUnit_Extensions_Selenium2TestCase_WebDriverException:未知错误:元素。。。在点(430139)处不可单击。其他元素将收到点击:(会

我的问题是: 我正在使用Selenium运行phpunit,以便在世界另一端的服务器上测试一个网站。因此,单击选项卡或新页面等操作会延迟几秒钟。我用Chromedriver启动Selenium服务器。 例如

运行上述操作时报告了一个错误,我将其捕获到一个xml文件中: ********::testSearch PHPUnit_Extensions_Selenium2TestCase_WebDriverException:未知错误:元素。。。在点(430139)处不可单击。其他元素将收到点击:(会话信息:chrome=57.0.2987.133)(驱动程序信息:chromedriver=2.29.461591(62ebf098771772160f391d75e589dc567915b233)

我试图做的是等待DOM完全加载,然后单击按钮。但我间歇性地出现上述错误。有人知道解决方法吗?这让我发疯!!

尝试显式等待。 “显式等待是您定义的等待特定条件发生后再继续执行代码的代码。提供了一些方便的方法,可帮助您编写只等待所需时间的代码。WebDriverWait与ExpectedCondition结合使用是实现此目的的一种方法。”

比如说,

// Wait for the page title to be 'My Page'. 

// Default wait (= 30 sec)
$driver->wait()->until(WebDriverExpectedCondition::titleIs('My Page'));


// Wait for at most 10s and retry every 500ms if it the title is not     correct.
$driver->wait(10, 500)->until(WebDriverExpectedCondition::titleIs('My Page'));

有许多准备好的条件可以传递给until()方法。所有这些条件都是WebDriverExpectedCondition的子类,包括elementtobelickable()。

我不知道这是否对您有帮助 但在java中,有一种方法可以等待某个项目可见

下面是它的写法

WebDriverWait Wait=new WebDriverWait(Driver, 10);
Wait.until(ExpectedConditions.visibilityOf(Driver.findElement(By.//your element locator)));

抱歉,我不知道如何用PHP编写它。

@GhostCat Fixed。请查看如何检查页面是否已加载-
WebDriverWait Wait=new WebDriverWait(Driver, 10);
Wait.until(ExpectedConditions.visibilityOf(Driver.findElement(By.//your element locator)));