获取与元素关联的事件列表

问题描述 投票:1回答:1

在Firefox中,可以在开发人员工具的Inspect Element中查看与每个元素相关的事件。enter image description here

我想拥有与其关联的元素和事件的列表,以编程方式。最好使用Selenium + python。

[我知道可以在Chrome的开发人员工具中使用getEventListeners函数,但在Selenium中无法使用。

我经历了this question中提供的大多数解决方案,但没有找到解决我的问题的方法。

我的最终目标是迭代抛出给定页面的html元素并执行每个元素的事件。

python selenium google-chrome-devtools puppeteer geckodriver
1个回答
1
投票

您可以在一定程度上使用python +硒(仅限Chrome):

body = driver.execute_cdp_cmd("Runtime.evaluate", {"expression": "document.body"})
listeners = driver.execute_cdp_cmd("DOMDebugger.getEventListeners", {"objectId": body["result"]["objectId"]})
© www.soinside.com 2019 - 2024. All rights reserved.