Can';PHP Selenium webdriver中的捕获异常

Can';PHP Selenium webdriver中的捕获异常,php,selenium-webdriver,exception-handling,Php,Selenium Webdriver,Exception Handling,我正试图捕捉在使用Facebook的PHP webdriver运行页面时超时的页面中的错误 page load和wait都被成功调用,但是wait()抛出的TimeOutException在两个catch块中都没有被捕获 try { $this->webDriver->get(self::BASE_URI.$uri_to_check); $this->webDriver->wait($webDriver, 100, 500)->until(

我正试图捕捉在使用Facebook的PHP webdriver运行页面时超时的页面中的错误

page load和wait都被成功调用,但是wait()抛出的TimeOutException在两个catch块中都没有被捕获

try {
    $this->webDriver->get(self::BASE_URI.$uri_to_check);
    $this->webDriver->wait($webDriver, 100, 500)->until(
    WebDriverExpectedCondition::titleIs('My Page'));
}
catch (TimeOutException $e) {
    return "Timeout Exception because".$e->getMessage();
}
catch (Exception $e) {
    return "Failed to load page because".$e->getMessage();
}

我怎样才能抓住这个问题?

我想您希望使用“隐式等待”而不是“显式等待”。您的示例是使用“显式等待”,即尝试多次sendcond,然后休眠(而不是超时)。请参阅


您为
wait()
方法提供了错误的参数。这些参数是
$timeout\u in_second
$interval\u in_millisecond
。因此,例如,如果您想等待15秒,并每隔500毫秒(0,5秒)检查一次标题,则必须这样调用:

$this->wd->wait(15, 500)->until(
    WebDriverExpectedCondition::titleIs('My Page')
);
还要注意默认参数(30秒,250毫秒),因此根本不需要传递它们:

$this->wd->wait()->until(
    WebDriverExpectedCondition::titleIs('My Page')
);

我也有同样的问题。我最终通过提供TimeoutException的完整路径修复了它:

try {
    $this->webDriver->get(self::BASE_URI.$uri_to_check);
    $this->webDriver->wait($webDriver, 100, 500)->until(
    WebDriverExpectedCondition::titleIs('My Page'));
}
catch (Facebook\WebDriver\Exception\TimeoutException $e) {
    return "Timeout Exception because".$e->getMessage();
}

然后捕获异常。

是否有任何错误发生?我不确定,但我认为这与页面加载以及要确保哪个元素可见有关。也许是这样的?同样的问题在这里。。。有什么想法吗?