首页 > 解决方案 > 使用 TouchActions 在 android app + appium 中滚动

问题描述

我正在对我的 Android 应用程序进行自动化测试,并且需要滚动才能看到滚动所需的字段。我尝试从这里
使用以下代码:

TouchActions action = new TouchActions(driver);
action.scroll(element, 10, 100);
action.perform();

运行此代码后,它给了我这个错误:

java.lang.ClassCastException:
io.appium.java_client.android.AndroidDriver cannot be cast to
org.openqa.selenium.interactions.HasTouchScreen

好吧,我知道我已经通过了TouchActionstype的驱动程序AndroidDriver

我将如何解决这个问题?

标签: appium-android

解决方案


请使用 TouchAction 而不是 TouchAction s

 TouchAction action = new TouchAction(androidDriver);
    int height = androidDriver.manage().window().getSize().height;
    int width = androidDriver.manage().window().getSize().width;
    action.press(PointOption.point(width / 2, height / 2))
            .moveTo(PointOption.point(width / 2, height * 3 / 4)).release().perform();

推荐阅读