【问题标题】:Scroll in android app + appium with TouchActions使用 TouchActions 在 android app + appium 中滚动
【发布时间】:2018-06-21 11:14:44
【问题描述】:

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

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

嗯,我知道我已经通过了TouchActions 中的驱动程序,它的类型是AndroidDriver

我该如何解决这个问题?

【问题讨论】:

  • 你到底想要什么?滚动或滚动到任何特定元素?
  • 现在,我需要滚动。谢谢
  • 好吧,它在您定义 TouchAction(); 的函数的最后一行给了我一个错误; “新的 TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(anchor, endPoint).release().perform();”那就是“构造函数TouchAction(AppiumDriver)未定义”你能帮我解决这个错误吗?

标签: appium-android


【解决方案1】:

请使用 TouchAction 而不是 TouchActions

 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();

【讨论】:

    猜你喜欢
    • 2020-04-06
    • 2019-01-22
    • 2019-01-10
    • 2016-12-16
    • 1970-01-01
    • 2018-07-05
    • 2020-04-22
    • 2020-05-22
    • 2019-02-07
    相关资源
    最近更新 更多