How to double click an element on Selenium Webdriver using JavaScript for Safari

半城伤御伤魂 提交于 2021-02-11 15:35:59

问题


I'm facing a problem double clicking an element on Safari using Java / Webdriver 2.48.

The tests are working fine on IE, Chrome, and Firefox but Actions are not supported on Safari. Currently I'm doing something like this

executor.executeScript("arguments[0].dblclick();", element);

or

executor.executeScript("arguments[0].dblclick;", element);

but is not working. Here is the error

arguments[0].dblclick is not a function. (In 'arguments[0].dblclick()', 'arguments[0].dblclick' is undefined) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 35 milliseconds Build info: version: '2.48.0', revision: 'b7b081a4f1289f17e8ecd38bc67e137c2a12e34a', time: '2015-10-07 09:50:14' System info: host: 'MacBook-Pro.local', ip: '10.0.1.7', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_25' Driver info: org.openqa.selenium.safari.SafariDriver Capabilities [{browserName=safari, takesScreenshot=true, javascriptEnabled=true, version=9.0, cssSelectorsEnabled=true, platform=MAC, secureSsl=true}] Session ID: null

I tried with dblclick and ondblclick but the double click was not executed, see the previous error.


回答1:


I was able to fix the issue using the following code

It works on Safari

var event = new MouseEvent('dblclick', {
'view': window,
'bubbles': true,
'cancelable': true
});

 document.querySelector("div[id='InProcessGrid']>div>table>tbody>tr.rowselected>td:nth-child(1)").dispatchEvent(event);

Here is more info about the issue

https://github.com/webdriverio/webdriverio/issues/231



来源:https://stackoverflow.com/questions/33419308/how-to-double-click-an-element-on-selenium-webdriver-using-javascript-for-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!