如何使用 capybara-webkit 或本机 QtWebKit 获取 DOM 元素单击处理程序?
我正在使用 capybara-webkit 并希望将事件处理程序绑定到 DOM 中元素的单击事件。即使使用本机 QtWebKit 调用的答案也可能足以让我弄清楚如何使用 Ruby 中的 webkit 驱动程序来做到这一点。我面临的挑战是事件处理程序是在 JavaScript 中以编程方式绑定的,而不是在 HTML 中,到目前为止我对如何执行此操作的搜索似乎都以如何单击或以其他方式触发 QWebView 中的事件而结束。我需要检查事件处理程序(即实际的函数定义),特别是绑定到事件的匿名函数,而不生成事件本身。任何帮助表示赞赏。
I'm using capybara-webkit and would like to get the event handler(s) bound to the click event of an element in the DOM. An answer even using native QtWebKit calls would probably be enough for me to figure out how to do it using the webkit driver in Ruby. The challenge I am having is that the event handlers are being bound programmatically in JavaScript, not in HTML, and my searches so far on how to do this all seem to end with how to click or otherwise trigger events in a QWebView. I need to inspect the event handler (i.e. the actual function definition), in particular anonymous functions bound to the event, without generating the event itself. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
page.execute_script
执行任意Javascript并返回结果。如果有问题的事件处理程序是使用 jQuery 绑定的,这将列出它们:这里有一个关于事件处理程序内省的完整答案:如何在调试时或从 JavaScript 代码中查找 DOM 节点上的事件侦听器?
You can execute arbitrary Javascript and return the result using
page.execute_script
. If the event handlers in question are bound using jQuery, this will list them:There's a complete answer on introspecting on event handlers here: How to find event listeners on a DOM node when debugging or from the JavaScript code?