问题描述
从Selenium Webdriver获取附加到节点的所有事件
Get all events attached to a node from selenium webdriver
我正在使用Selenium-python,我想执行一个JavaScript脚本(通过 driver.execute_script('my js script')
.
I'm using selenium-python and I'd like to execute a javascript script (through driver.execute_script('my js script')
.
此脚本使用 getEventListeners
,该功能仅在 Chrome 上可用.我成功使用了
This script uses getEventListeners
which is only available on Chrome.I used successfully
driver = webdriver.Chrome('path/to/chromedriver')
启动Chrome浏览器.用 getEventListeners(myNode)
执行我的脚本,我得到类似的东西:
to launch a chrome browser. Executing my script with getEventListeners(myNode)
I get something like:
getEventListeners
可通过命令行API使用,但我无法使其在selenium中起作用.有解决方案吗?还有其他方法可以将所有事件绑定到元素吗?(尤其是Click事件)
getEventListeners
is available through the Command Line API but I can't make it work from selenium. Is there a solution for this? Is there any other way to get all events binded to an element ? (especially Click event)
欢呼
推荐答案
不幸的是,答案是:无法通过 ChromeDriver
访问 getEventListeners
.如评论所述,这是设计:
Sadly the answer is: Accessing getEventListeners
via ChromeDriver
is not possible. This is -- as mentioned in the comments -- by design:
根据问题报告设置为 WontFix
.
但是:
查看此答案,以查找不使用 getEventListeners
附加到节点的所有事件.
Check out this answer for finding all events attached to a node without using getEventListeners
.
这篇关于从Chrome WebDriver访问getEventListeners(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!