How to fire mouse wheel event in Firefox with JavaScript?

前端 未结 1 381
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 02:28

I\'m trying to do automated testing with WebDriver, but it currently has no ability to simulate mouse wheel events. As a workaround I\'m trying to fire these events with Ja

相关标签:
1条回答
  • 2020-12-30 02:47

    Well,

    1. In the Mozilla part of the code, if you're listening for DOMMouseScroll you should dispatch a DOMMouseScroll event too, no? (mousewheel seems to be a Microsoft invention copied by webkit, but not Gecko).
    2. Instead of setting (readonly) properties on the event, you're supposed to call the appropriate init...() method, which for the mouse event is initMouseEvent(). (spec)

    Here's a fixed up testcase, which works in Firefox: http://jsfiddle.net/6nnMV/

    Probably not useful to you, but may be of interest to other people looking to simulate events, here's how (privileged) unit tests in mozilla simulate 'real' events: http://hg.mozilla.org/mozilla-central/annotate/a666b4f809f0/testing/mochitest/tests/SimpleTest/EventUtils.js#l248

    0 讨论(0)
提交回复
热议问题