2

WebdriverIO supplies a doubleClick() command. Unlike some other commands, such as leftClick(), doubleClick() does not have any x y parameters. I am unable to double click on specific x y positions on one particular component. I would like to do this because a child element should be inserted at the exact double click location.

I have used moveToObject() to first move the cursor to a specific location but doubleClick does not pick this up. It always double clicks the center of a component.

Also there is no command like 'elementIdDoubleClick`. And, actions have not been implemented yet.

Does anyone have an idea how I can double click on specific x y co-ordinates within a component?

cham
  • 4,095
  • 4
  • 32
  • 48
  • Just a random guess; what happens when you call `leftClick()` twice? – Chris G Jun 10 '18 at 22:35
  • Nice out of the box thinking @ChrisG ! I had a little try and it doesn't go but I will mess around some more and report back if it works – cham Jun 10 '18 at 22:41

2 Answers2

1

You can use doDoubleClick(); first move to your element and then use doDoubleClick();

return this.app.client.moveToObject(element,5,5).doDoubleClick();

But make sure moveToObject() and doDoubleClick() are deprecated.

WDIO will not remove them without releasing an alternative api.

And make sure you use webdriverOptions: ({deprecationWarnings : false}) in your app launch config to silent these warnings.

Bharath Kumar S
  • 1,332
  • 2
  • 8
  • 25
1

doDoubleClick() doesn't seem to work on Chrome for me, and I'm not sure why. I see ChomeDriver is implementing actions as I write this. Once that's done, you'll be able to do:

browser.moveToObject(someElement, x, y);
browser.actions().mouseDown().mouseUp().mouseDown().mouseUp().perform();

But right now, when I do that with ChromeDriver 2.45, I get:

Error: unimplemented command: session/c4dae3dead96649fc7c26f75709257da/actions

So if you're not in the far off future, this is what is working for me:

function doubleClick(someElement, x, y) {
  let attempt = 0;
  let timeToDoubleClick;
  do {
    browser.moveToObject(someElement, x, y);
    let startTime = Date.now();
    browser.buttonPress(0).buttonPress(0);
    timeToDoubleClick = Date.now() - startTime;
    console.log("Time to double click: " + timeToDoubleClick);

    if (timeToDoubleClick > 500)  {
      console.log("Waiting 10 seconds to allow the CPU to breath / check to see if a tab has opened...");
      browser.pause(10000);

      // In my case I'm expecting a new tab to open
      if(browser.getTabIds().length > 1) {
        // The tab opened!
        timeToDoubleClick = 0;
      }
    }
  } while(timeToDoubleClick > 500 && attempt++ <= 5);

  if(attempt > 5) {
    throw new Error("Could not manage to double click!");
  }
}
Ryan Shillington
  • 15,463
  • 10
  • 75
  • 85