javascript 如何使用量角器双击元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25894403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I perform a double click on an element with Protractor?
提问by Alan2
I would like to double click on an element but I could not find a way to do this in the document API. I found some references dating back to 2013 but I know things have changed a lot.
我想双击一个元素,但在文档 API 中找不到执行此操作的方法。我发现了一些可追溯到 2013 年的参考资料,但我知道情况已经发生了很大变化。
Can someone help and tell me how I can perform a double click.
有人可以帮助并告诉我如何执行双击。
Thanks
谢谢
回答by alecxe
Always remember that protractor
is a wrapper around webdriverjs.
永远记住这protractor
是webdriverjs的包装器。
doubleClick()
is available in browser.actions()
:
doubleClick()
可在browser.actions()
:
browser.actions().doubleClick(element(by.id('mybutton'))).perform();
回答by Kyle Westendorf
For anyone looking at this in 2019, this still works. Just know thatProtractor selectors use the Locator object to find elements. The above solution uses the webElement object. So if you're using Protractor to find your element, you'll need to do something like browser.actions().doubleClick(myElement.getWebElement()).perform();
对于在 2019 年看到这个的人来说,这仍然有效。只知道Protractor 选择器使用Locator 对象来查找元素。上面的解决方案使用了 webElement 对象。因此,如果您使用量角器来查找元素,则需要执行以下操作browser.actions().doubleClick(myElement.getWebElement()).perform();
回答by user3422841
var el=element(by.id('id'));
browser.executeAsyncScript(function() {
var evt=new MouseEvent('dblclick', {bubbles: true,cancelable: true,view: window});
var callback = arguments[arguments.length - 1];
arguments[0].addEventListener('dblclick',callback);
arguments[0].dispatchEvent(evt);
},el).then(function(){...});