Listening for a WebElement search event

This event is triggered when the WebDriver searches for a WebElement on the web page using findElement() or findElements(). There are, again, two methods associated with this event:

public void beforeFindBy(By by, WebElement element, WebDriver driver)

The preceding method is invoked just before WebDriver begins searching for a particular WebElement on the page. For parameters, it sends the locating mechanism, that is, the WebElement that is searched for, and the WebDriver instance that is performing the search:

public void afterFindBy(By by, WebElement element, WebDriver driver)

Similarly, the EventFiringWebDriver class calls the preceding method after the search for an element is over and the element is found. If there are any exceptions during the search, this method is not called, and an exception is raised.