2
在Android中,我需要在我的应用程序中拖动一个对象并在保留该对象的同时拍摄屏幕截图。在Appium中拖动屏幕截图
我知道有采用触摸操作的两种方式(我还没有考虑更高层次的方法,如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
该计划的第二触摸操作过程中出现故障,即截图被成功取出,但我没有用这种方式抓住它后释放对象的方法。
任何想法?
不知道我理解你正确,但如果你是在暗示我尝试.release(x,y),没有这样的方法(至少在Appium的Java客户端中)。 –
尽管我无法直接使用你的答案,但是你让我朝着正确的方向前进,所以非常感谢!我的最终代码如下所示: 'touchAction.moveTo(0,0).release()。perform();' 其中touchAction指的是第一个TouchAction对象: 'TouchAction touchAction = new TouchAction(driver).press X,Y)。 etc ..' 通过使用对同一个touchAction的引用,并通过“移动”坐标0,我能够完成第二个动作。 –