EventFiringWebDriver

使用 EventFiringWebDriver 。你可以將 WebDriverEventListener 附加到它並覆蓋 methodes,即 onException 方法:

EventFiringWebDriver driver = new EventFiringWebDriver(new FirefoxDriver());
WebDriverEventListener listener = new AbstractWebDriverEventListener() {
    @Override
    public void onException(Throwable t, WebDriver driver) {
        // Take action
    }
};
driver.register(listener);