Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get list of events associated with a DOM elements

In Firefox it is possible to see events associated with each element in Inspect Element of developers tools. enter image description here

I want to have a list of elements and events associated with it, programmatically. preferably using selenium+python.

I know that there is getEventListeners function that can be used in developer tools of Chrome, but it is not accessible in Selenium.

I went through most of the solutions offered in this question, but found nothing to resolve my problem.

My ultimate goal is to iterate throw html elements of a given page and execute each element's events.

like image 378
HadiRj Avatar asked Jun 10 '20 11:06

HadiRj


1 Answers

You can do this to a certain extent with python + selenium (chrome only):

body = driver.execute_cdp_cmd("Runtime.evaluate", {"expression": "document.body"})
listeners = driver.execute_cdp_cmd("DOMDebugger.getEventListeners", {"objectId": body["result"]["objectId"]})
like image 116
pguardiario Avatar answered Sep 23 '22 11:09

pguardiario