在 Appium 中拖动时截图

Take a screenshot during dragging in Appium

在 Android 中,我需要在我的应用程序中拖动一个对象并截屏,同时仍然拿着该对象。

我知道有两种使用触摸操作的方法(我什至没有考虑更高级别的方法,例如 swipe(),因为它们让我对触摸操作的控制更少):

new TouchAction(driver).press(element).moveTo(x,y).release().perform();

driver.performTouchAction(new TouchAction(driver).press(element).moveTo(x,y).release());

当我尝试将触摸操作分成两部分,并在其间插入屏幕截图时,如下面的代码所示:

new TouchAction(driver)
    .press(x,y)
    .moveTo(newX,newY)
    .perform();

takeScreenshot(); // My own implementation for readability 

new TouchAction(driver)
    .release()
    .perform();

我收到以下错误:

org.openqa.selenium.WebDriverException: ERROR running Appium command: Cannot read property 'x' of null
Command duration or timeout: 14 milliseconds

第二次触摸时程序失败,即截图成功,但是我用这种方式抓取对象后无法释放

有什么想法吗?

通过查看您的问题

new TouchAction(driver)
    .release()
    .perform();

为发布提供一些 x 和 y 位置来发布试试看可能有效