【问题标题】:How to scroll up/down in appium-android如何在 appium-android 中向上/向下滚动
【发布时间】:2019-12-24 07:34:46
【问题描述】:

我有一个应用页面,我需要垂直滚动才能到达应用的某个元素。

我已经用谷歌搜索并尝试了许多解决方案。许多命令已被弃用,并且在 appium 中不再支持。此外,堆栈中以前的问题/答案对我没有帮助。 我正在使用 appium v​​1.13.0 + Java (IntelliJ)。

有时我会看到这个错误:

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

无论如何,我的问题不仅仅是解决上述错误。我正在寻找可行且正确的命令来使用 appium 进行滚动操作。 请把完整的示例项目带给我,因为我是初级的。 谢谢

【问题讨论】:

    标签: java appium appium-android


    【解决方案1】:

    我的刷卡方法:

    public void swipe(int startX, int startY, int endX, int endY, int msDuration) {
        TouchAction touchAction = new TouchAction(mDriver);
        touchAction.press(PointOption.point(startX, startY))
                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(msDuration)))
                .moveTo(PointOption.point(endX, endY))
                .release();
    
        touchAction.perform();
    }
    

    【讨论】:

      【解决方案2】:

      试试这个

      String scrollViewContainer_finder = "new UiSelector().resourceIdMatches(\".*id/your_scroll_view_id\")";
      String neededElement_finder = "new UiSelector().resourceIdMatches(\".*id/elemnt1\")";
      
      WebElement abc = driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + scrollViewContainer_finder + ")" +
                      ".scrollIntoView(" + neededElement_finder + ")"));
      

      【讨论】:

      • 工作。我也用这个:UiSelector().text(\"your_target\")";
      【解决方案3】:

      对于垂直/水平滑动,我使用的是 TouchAction:

      TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);
      touchAction.press(startPoint)
                 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(waitBetweenSwipes)))
                 .moveTo(endPoint)
                 .release()
                 .perform();
      

      【讨论】:

      • 我应该用什么来代替“startPoint”和“endPoint”?
      猜你喜欢
      • 2018-12-03
      • 2016-05-16
      • 2018-01-01
      • 2019-01-03
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      • 2020-03-30
      相关资源
      最近更新 更多