How to tap and hold (Long press) using appium for Android?

心已入冬 提交于 2020-06-24 10:19:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!