Goal: 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.
Example of the expected result:
This is an illustrative example to understand what I need:
- Event name: Mouse Left click
- Button Name: Login
- Class name of the button: login-button
...
- Event name: Mouse Left click
- Button name: Next
- Class name of the button: next-button
Experience in python: Beginner
Python interpreter: 3.7
Question: 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?.
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.
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?.
Thank you very much for your help and please forgive me if I used incorrectly any concept.
Python 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()