Listeners in Selenium



  • The listener is used to track any activity. There are many listeners available in selenium and testNG.

  • WebDriverEventListener is provided in WebDriver to track events those take place in WebDriver during script execution.

  • If we want to see closely how all actions are triggered either this is the click event of a button, URL or navigating back and forward in browser or some exception occur while executing script. To take screenshot once some exceptions occur during execution.

  • So WebDriverEventListener has been just the answer of all the queries.

  • Create any class for tracking events. Implements WebDriverEventListener to any class and override all methods available in that interface.

  • We have created a class with name : TrackChangesInApplication

steps to add unimplemented methods in selenium

  • Click on no 3 that is - Add unimplemented methods.

  • You will see automatically many methods comes with an editor. Just write some testing text there like below.


Once this is finished we will create test scripts and we will initialise a driver with listener just we wrote.


  • We will observe that every operation is tracked here and so if we want to do anything we can do it here itself in listener.

  • If we want to put some wait time before every find by() method. If there is no listener then what we will have to do is write code again and again before every find by() method.

  • Instead we can use above listener so that we need not write that code again and again.


This code will execute every time we do “find by” to any control.