问题
Is there any code to tap and hold on Appium? i use python , is there any command to support it ?
For double click i used click on element twice, for tap and hold i am not getting any solution
回答1:
Yes, you can use TouchAction class to longPress any element. Try this:
TouchAction action = new TouchAction();
action.longPress(webElement).release().perform();
回答2:
Need to pass driver
TouchAction action = new TouchAction(driver);
action.longPress(webElement).release().perform();
回答3:
In latest Java client versions below will work.
AndroidTouchAction touch = new AndroidTouchAction (driver);
touch.longPress(LongPressOptions.longPressOptions()
.withElement (ElementOption.element (element)))
.perform ();
System.out.println("LongPressed Tapped");
回答4:
Here is the update for Java Client: 5.0.4
WebElement recBtn = driver.findElement(MobileBy.id("img_button"));
new TouchAction((MobileDriver) driver).press(recBtn).waitAction(Duration.ofMillis(10000)).release().perform();
回答5:
It should be like this. The duration is calculated in milliseconds, so it need to multiply by 1000 as 1 second.
TouchAction action = new TouchAction(driver);
action.longPress(webElement,duration*1000).release().perform();
回答6:
This works:
TouchActions action = new TouchActions(driver);
action.longPress(element);
action.perform();
来源:https://stackoverflow.com/questions/29298096/how-to-tap-and-hold-long-press-using-appium-for-android