- Learn Selenium
- Unmesh Gundecha Carl Cocchiaro
- 107字
- 2021-06-24 13:25:50
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.