1public class EventFiringWebDriverTest {2 public static void main(String[] args) {3 WebDriver driver = new FirefoxDriver();4 EventFiringWebDriver eventDriver = new EventFiringWebDriver(driver);5 EventHandler handler = new EventHandler();6 eventDriver.register(handler);7 eventDriver.findElement(By.name("q")).sendKeys("Selenium WebDriver");8 eventDriver.findElement(By.name("btnG")).click();9 eventDriver.quit();10 }11}12class EventHandler implements WebDriverEventListener {13 public void beforeNavigateTo(String url, WebDriver driver) {14 System.out.println("Before navigating to: '" + url + "'");15 }16 public void afterNavigateTo(String url, WebDriver driver) {17 System.out.println("Navigated to:'" + url + "'");18 }19 public void beforeChangeValueOf(WebElement element, WebDriver driver) {20 System.out.println("Value of the:" + element.toString()21 + " before any changes made");22 }23 public void afterChangeValueOf(WebElement element, WebDriver driver) {24 System.out.println("Element value changed to: " + element.toString());25 }26 public void beforeClickOn(WebElement element, WebDriver driver) {27 System.out.println("Trying to click on: " + element.toString());28 }29 public void afterClickOn(WebElement element, WebDriver driver) {30 System.out.println("Clicked on: " + element.toString());31 }32 public void beforeNavigateBack(WebDriver driver) {33 System.out.println("Navigating back to previous page");34 }35 public void afterNavigateBack(WebDriver driver) {36 System.out.println("Navigated back to previous page");37 }38 public void beforeNavigateForward(WebDriver driver) {39 System.out.println("Navigating forward to next page");40 }41 public void afterNavigateForward(WebDriver driver) {42 System.out.println("Navigated forward to next page");43 }44 public void onException(Throwable error, WebDriver driver) {45 System.out.println("Exception occured: " + error);46 }47 public void beforeFindBy(By by, WebElement element, WebDriver driver) {48 System.out.println("Trying to find Element By : " + by.toString());49 }50 public void afterFindBy(By by, WebElement element, WebDriver driver) {51 System.out.println("Found Element By : " + by.toString());52 }