SEMrush

Listeners in Java

EventFiringWebDriver is a class and is used to wrap your WebDriver around to throw events and WebDriverEventListner is an interface which you have to implement to catch thewebdriver events.

EventFiringWebDriver  ---------->   Throws 
WebDriverEventListner -----------> Catches


EventFiringWebDriver - use this class and you will get  two methods
  • register(WebDriverEventListener eventListener) - register and listen to the WebDriver events 
  • unregister(WebDriverEventListener eventListener)unregister means detach and stop listening to WebDriver events


along with the regular webdriver methods ( findElementById , findElementByTagName )
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.events.WebDriverEventListener;
public class EventHandler implements WebDriverEventListener{
public void afterChangeValueOf(WebElement arg0, WebDriver arg1) {
// TODO Auto-generated method stub
System.out.println("inside method afterChangeValueOf on " + arg0.toString());
}
public void afterClickOn(WebElement arg0, WebDriver arg1) {
// TODO Auto-generated method stub
System.out.println("inside method afterClickOn on " + arg0.toString());
}





Comments