testautomation
testautomation

Reputation: 33

How to click and hold using the webdriverio

I am trying to figure out how to click and hold using webdriverio. In selenium it is like this:

WebElement elementToInteractWith = driver.findElement(By.id("myElement"));

Actions holdClick = new Actions(driver);

holdClick.clickAndHold(elementToInteractWith).perform();

//wait for however long you need to hold

holdClick.release().perform();

However i am not sure how to do that in webdriver io but cannot find anything on the documentation

Upvotes: 0

Views: 3998

Answers (3)

testautomation
testautomation

Reputation: 33

nothing seems to work above but i tried this in the end and it worked:

browser.$('//div[@data-test="touch-area"]').moveTo(0,0)
browser.buttonDown(0);
browser.pause(3000)

Upvotes: 0

Nate R
Nate R

Reputation: 97

You can test it with buttonDown on w3school page.

browser.url("https://www.w3schools.com/css/css3_buttons.asp");
browser.buttonDown("//button[text()='Default Button']");
browser.pause(5000);
browser.buttonUp("//button[text()='Default Button']");

However, this is for webdriverio v4. It says this is deprecated soon, but maybe V5 has the same api.

Upvotes: 1

Raju
Raju

Reputation: 2509

I believe you can try this.

https://webdriver.io/docs/api/jsonwp.html#buttondown

You can have a pause after this for the time you need to and then buttonup should follow.

Cheers!

Upvotes: 2

Related Questions