title: WebElement logging which were clicked by the user
body: <p><strong>Goal:</strong> Record all these specific actions: onKeyboardEvent and onMouseEvent performed by one user on a particular website. This recording includes logging, for example, the button name, class name of that button and so on of a website only when the user clicked on that respective button. I want to create this logger with python.</p>
  
  <p><strong>Example of the expected result:</strong></p>
  
  <p>This is an illustrative example to understand what I need:</p>
  
  <ul>
  <li>Event name: Mouse Left click</li>
  <li>Button Name: Login</li>
  <li>Class name of the button: login-button </li>
  </ul>
  
  <p>...</p>
  
  <ul>
  <li>Event name: Mouse Left click</li>
  <li>Button name: Next</li>
  <li>Class name of the button: next-button</li>
  </ul>
  
  <p><strong>Experience in python:</strong> Beginner</p>
  
  <p><strong>Python interpreter:</strong> 3.7</p>
  
  <p><strong>Question:</strong> How can I record or log the button name or class name of that button when a User clicked on it on a particular website that it opened?. </p>
  
  <p>I checked Selenium and Python in order to achieve my goal. What I understood so far, selenium hat listener class and Selenium is which opens the browser and starts the event listening under that particular browser. However, in my case the user is who opens a particular website on Chrome, Firefox or Internet explorer and I need a program in python to record what the user is doing in that website.</p>
  
  <p>The code attached below did not record or log anything. Besides, it did not connect to the respective browser that the user open but it listens only the session started by Selenium. Could anyone tell me if I am using the right approach or if I should use another to reach my goal?.</p>
  
  <p>Thank you very much for your help and please forgive me if I used incorrectly any concept.  </p>
  
  <p><strong>Python code:</strong></p>
  
  <pre><code>import time
  from selenium import webdriver
  from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener
  
  class MyListener(AbstractEventListener):
      def before_click(self, element, driver):
          driver.get_attribute("tag")
          print ("Event : before element click()")
  
      def after_click(self, element, driver):
          print("clicked on %s" %element)
  
  driver = webdriver.Chrome('Webdrivers\Chrome_80\\chromedriver.exe')
  driver = EventFiringWebDriver(driver, MyListener())
  driver.get("https://google.com")
  elem = driver.find_element_by_name("q")
  time.sleep(20)
  driver.close()
  </code></pre>