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

后端 未结 6 1256
渐次进展
渐次进展 2021-02-06 14:06

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 no

相关标签:
6条回答
  • 2021-02-06 14:57

    Yes, you can use TouchAction class to longPress any element. Try this:

    TouchAction action = new TouchAction();
    action.longPress(webElement).release().perform();
    
    0 讨论(0)
  • 2021-02-06 15:03

    Need to pass driver

    TouchAction action = new TouchAction(driver);
    action.longPress(webElement).release().perform();
    
    0 讨论(0)
  • 2021-02-06 15:03

    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();
    
    0 讨论(0)
  • 2021-02-06 15:05

    This works:

    TouchActions action = new TouchActions(driver);
    action.longPress(element);
    action.perform();
    
    0 讨论(0)
  • 2021-02-06 15:06

    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");
    
    0 讨论(0)
  • 2021-02-06 15:08

    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();
    
    0 讨论(0)
提交回复
热议问题