无法在PHP Selenium webdriver中捕获异常

I'm trying to catch errors in pages that timeout when running them with Facebook's PHP webdriver.

The page load and wait are both succesfully called, but the TimeOutException thrown by wait() doesn't get caught in either catch block.

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();
}

How can I catch this?

I think you're looking to use "Implicit wait" as opposed to "Explicit wait". Your example is making use of "Explicit wait" i.e. will try for a number of sendcond then sleep (not timeout). Refer to the php-driver wiki.

https://github.com/facebook/php-webdriver/wiki/HowTo-Wait

You are giving wrong parameters to the wait() method. The params are $timeout_in_second and $interval_in_millisecond. So if you for example want to wait up to 15 seconds and check the title every 500 ms (0,5 sec), you must call it this way:

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

And also note the default parameters (30 seconds, 250 milliseconds), so you don't need to pass them at all:

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