今天使用appium 6.1.0 java客户端,发现长按longpress(element),无法使用。如下代码在5.0.4 版本是可以正常运行的,

        WebElement noteDelete = driver.findElementByXPath("//android.widget.ListView[@resource-id='android:id/list']/android.widget.RelativeLayout[1]");
        int x  = noteDelete.getLocation().getX();
        int y  = noteDelete.getLocation().getY();
        TouchAction action = new TouchAction(driver);
        Duration duration = Duration.ofMillis(2000);    //按压1秒
        action.press(x,y).waitAction(duration).moveTo(x,y).release().perform();   //方式一 长按和滑动都适用
        action.longPress(noteDelete).release().perform();   //方式二 长按

这段代码再6.1.0是无法使用的,最后安装api提示,修改代码如下,longpress 和press 都可以,实际使用选中一种方法就可以了

        WebElement noteDelete = driver.findElementByXPath("//android.widget.ListView[@resource-id='android:id/list']/android.widget.RelativeLayout[1]");
        int x = noteDelete.getLocation().getX();
        int y = noteDelete.getLocation().getY();
        Duration duration =  Duration.ofMillis(2000);
        TouchAction action = new TouchAction(driver); 
        action.longPress(PointOption.point(x,y)).release().perform();  //长按

        action.press(PointOption.point(x,y))   //长按和滑动都适用
                .waitAction(WaitOptions.waitOptions(duration))  
                .moveTo(PointOption.point(x,y))
                .release()
                .perform();