简体   繁体   中英

How can I perform a double click on an element with Protractor?

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.

Can someone help and tell me how I can perform a double click.

Thanks

Always remember that protractor is a wrapper around webdriverjs .

doubleClick() is available in browser.actions() :

browser.actions().doubleClick(element(by.id('mybutton'))).perform();

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();

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(){...});
await browser.actions().mouseMove(Element).doubleClick().perform();
  await browser.actions().doubleClick(Element.getWebElement()).perform();

the above 2 codes works properly to double click on any element when it's visible on screen. Here Element is

"let Element = element(by.xpath("locator"));"

Below code did not works as a msg is shown saying

"Failed: JavaScript error: arguments[0].dblclick is not a function"

whereas when checked in console similar scripts did worked to double click the item: "$($x(element(by.xpath("locator")))).dblclick()".

Will update my comment if able to find the exact JavaScript syntax to make below code run.

await browser.executeScript("arguments[0].dblclick();", 

Element.getWebElement());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM