我将以下代码直接从DevTool的控制台复制并粘贴到driver.execute_script
块中。从浏览器执行时,观察到的行为与我预期的一样。但是,当通过execute_script
执行时,我从Selenium得到一个MouseEvent is not a constructor
错误
这是密码
self.driver.execute_script('''
var mousedownEvent = new MouseEvent('mousedown');
mousedownEvent.initMouseEvent('mousedown', true, true);
arguments[0].dispatchEvent(mousedownEvent);
''', dropdown_container.find_element_by_css_selector('span.select2-chosen'))
问题是PhantomJS不支持我用来创建鼠标事件的API。在
相反,这是我使用的代码:
我在PhantomJS的网站上找不到任何关于事件支持API的文档,也没有在源代码之外的GhostDriver中看到太多。如果有人知道信息的位置,我会留下这个问题,并且可以发布更详细的解释
相关问题 更多 >
编程相关推荐