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