title: Selenium - EventFiringWebDriver beforeFindBy and afterFindBy methods fires same event multiple times
body: <p>I have implemented WebDriverEventListener in my project to log events. I am facing an issue that same events are fired multiple times for <strong>beforeFindBy</strong> and <strong>afterFindBy</strong> methods in WebDriverEventListener Interface though I registered eventListener only once. Not sure what went wrong. My code goes as follows. Please help on this.</p>
  
  <p><strong>PageClass</strong></p>
  
  <pre><code>package pageobjects;
  
  import org.openqa.selenium.TimeoutException;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.support.FindBy;
  import org.openqa.selenium.support.PageFactory;
  import org.openqa.selenium.support.ui.ExpectedConditions;
  import org.openqa.selenium.support.ui.WebDriverWait;
  
  public class TestHome {
  
      WebDriverWait wait;
      WebDriver driver;
  
      @FindBy(className = "noo-search")
      public WebElement lnkSearch;
  
      public TestHome(WebDriver driver) {
          PageFactory.initElements(driver, this);
          this.driver = driver;
      }
  
      public void clickSearchIcon() {
          clickElement(lnkSearch);
      }
  
      public void waitForElementToBeClickable(WebElement element) {
          try {
              wait = new WebDriverWait(driver, 10);
              wait.until(ExpectedConditions.elementToBeClickable(element));
          } catch (TimeoutException e) {
              throw new TimeoutException("Element not clickable within the given time..");
          }
      }
  
      public void clickElement(WebElement element) {
          waitForElementToBeClickable(element);
          element.click();
      }
  }
  </code></pre>
  
  <p><strong>Listener</strong></p>
  
  <pre><code>package listeners;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.OutputType;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.support.events.WebDriverEventListener;
  
  public class EventHandler implements WebDriverEventListener {
  
      @Override
      public void beforeAlertAccept(WebDriver webDriver) {
  
      }
  
      @Override
      public void afterAlertAccept(WebDriver webDriver) {
  
      }
  
      @Override
      public void afterAlertDismiss(WebDriver webDriver) {
  
      }
  
      @Override
      public void beforeAlertDismiss(WebDriver webDriver) {
  
      }
  
      @Override
      public void beforeNavigateTo(String s, WebDriver webDriver) {
          System.out.println("Before Navigate to " + s);
      }
  
      @Override
      public void afterNavigateTo(String s, WebDriver webDriver) {
          System.out.println("After Navigate to " + s);
      }
  
      @Override
      public void beforeNavigateBack(WebDriver webDriver) {
  
      }
  
      @Override
      public void afterNavigateBack(WebDriver webDriver) {
  
      }
  
      @Override
      public void beforeNavigateForward(WebDriver webDriver) {
  
      }
  
      @Override
      public void afterNavigateForward(WebDriver webDriver) {
  
      }
  
      @Override
      public void beforeNavigateRefresh(WebDriver webDriver) {
  
      }
  
      @Override
      public void afterNavigateRefresh(WebDriver webDriver) {
  
      }
  
      @Override
      public void beforeFindBy(By by, WebElement webElement, WebDriver webDriver) {
          System.out.println("Before finding element " + by);
      }
  
      @Override
      public void afterFindBy(By by, WebElement webElement, WebDriver webDriver) {
          System.out.println("After finding element " + by);
      }
  
      @Override
      public void beforeClickOn(WebElement webElement, WebDriver webDriver) {
  
      }
  
      @Override
      public void afterClickOn(WebElement webElement, WebDriver webDriver) {
  
      }
  
      @Override
      public void beforeChangeValueOf(WebElement webElement, WebDriver webDriver, CharSequence[] charSequences) {
  
      }
  
      @Override
      public void afterChangeValueOf(WebElement webElement, WebDriver webDriver, CharSequence[] charSequences) {
  
      }
  
      @Override
      public void beforeScript(String s, WebDriver webDriver) {
  
      }
  
      @Override
      public void afterScript(String s, WebDriver webDriver) {
  
      }
  
      @Override
      public void beforeSwitchToWindow(String s, WebDriver webDriver) {
  
      }
  
      @Override
      public void afterSwitchToWindow(String s, WebDriver webDriver) {
  
      }
  
      @Override
      public void onException(Throwable throwable, WebDriver webDriver) {
  
      }
  
      @Override
      public &lt;X&gt; void beforeGetScreenshotAs(OutputType&lt;X&gt; outputType) {
  
      }
  
      @Override
      public &lt;X&gt; void afterGetScreenshotAs(OutputType&lt;X&gt; outputType, X x) {
  
      }
  
      @Override
      public void beforeGetText(WebElement webElement, WebDriver webDriver) {
  
      }
  
      @Override
      public void afterGetText(WebElement webElement, WebDriver webDriver, String s) {
  
      }
  }
  </code></pre>
  
  <p><strong>TestClass</strong></p>
  
  <pre><code>import listeners.EventHandler;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  import org.openqa.selenium.support.events.EventFiringWebDriver;
  import pageobjects.TestHome;
  
  public class TestClass {
  
      static WebDriver driver;
  
      public static void main(String[] args) {
  
          driver = new ChromeDriver();
          EventFiringWebDriver eDriver = new EventFiringWebDriver(driver);
          EventHandler listener = new EventHandler();
          eDriver.register(listener);
  
          eDriver.get("https://shop.demoqa.com");
          TestHome home = new TestHome(eDriver);
          home.clickSearchIcon();
  
      }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Starting ChromeDriver 2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 47488
  Only local connections are allowed.
  Dec 30, 2019 11:56:46 PM org.openqa.selenium.remote.ProtocolHandshake createSession
  INFO: Detected dialect: OSS
  Before Navigate to https://shop.demoqa.com
  After Navigate to https://shop.demoqa.com
  Before finding element By.className: noo-search
  After finding element By.className: noo-search
  Before finding element By.className: noo-search
  After finding element By.className: noo-search
  Before finding element By.className: noo-search
  After finding element By.className: noo-search
  
  Process finished with exit code 0
  </code></pre>