appiumappium-android

How to use longpress in appium?


I had tried lots of different longpress method but it do not work currently with appium.

TouchAction action = new TouchAction();
action.longPress(webElement).release().perform();

above method do not provide duration to hold and press element.


Solution

  • To press and hold (longpress) any element, i have mentioned code below which is working perfectly.

     WebElement holdElement= driver.findElementById("element");
    
      AndroidTouchAction t = new AndroidTouchAction(driver);   
    
      t.longPress(LongPressOptions.longPressOptions()
      .withElement(ElementOption.element(holdElement))
      .withDuration(Duration.ofMillis(5000)))
      .release()
      .perform();
    

    here we can provide duration to press and hold element.