Listening for an exception

This event occurs when the WebDriver comes across an exception. For instance, if you try to search for a WebElement using findElement(), and that element doesn't exist on the page, the driver throws an exception (NoSuchElementException). At this point, this event is triggered, and the following method gets notified:

public void onException(java.lang.Throwable throwable, WebDriver driver)

In all the after<<event>> methods, we have seen that they will not be invoked if the driver comes across any exception. In that case, instead of those after<<event>> methods, the onException() method is invoked and the throwable object and the WebDriver object are sent to it as parameters.

Get Selenium WebDriver 3 Practical Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.