16

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

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Alan2
  • 23,493
  • 79
  • 256
  • 450
  • 1
    Could you share the reasons to unaccept the answer? Is there anything that can be improved in it? Thanks. – alecxe Oct 14 '14 at 05:48

4 Answers4

27

Always remember that protractor is a wrapper around webdriverjs.

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

browser.actions().doubleClick(element(by.id('mybutton'))).perform();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • protractor is a wrapper around `selenium-webdriver`. [WebdriverIO](http://webdriver.io/) is a complete different project that does basically the same but in an other way (it's callback based chaining). – ChristianB Sep 18 '14 at 15:45
1

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

0
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(){...});
user3422841
  • 95
  • 1
  • 13
0
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());
demouser123
  • 4,108
  • 9
  • 50
  • 82