How might you consequently click a screen capture at whatever point an exception happens?
For this you should utilize the class and need to actualize the technique for the interface. See the code model given beneath.
WebDriver browser = new FirefoxDriver();
EventFiringWebDriver eventDriver = new EventFiringWebDriver(browser).register(new AbstractWebDriverEventListener() {
@Override
public void onException(Throwable throwable, WebDriver browser) {
// Take the screenshot using the Webdriver.
File screen = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can copy the screenshot somewhere on your system.
FileUtils.copyFile(screen, new File("c:Selenium Testing Questionsscreen.png"));
}
});
try {
eventDriver.findElement(By.id("test"));
fail("Caught the Expected exception."); // Intentionally causing the exception for demo.
} catch (NoSuchElementException e) {
// Triggering point for the event.
}