【问题标题】:Can't scroll backward using UIAutomator2无法使用 UIAutomator2 向后滚动
【发布时间】:2020-03-31 05:08:02
【问题描述】:

我正在尝试使用下面的代码 sn-p 向后滚动,但它会抛出错误

  • 代码sn-p

    try {
    
        getTLDriver().findElements(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).setAsVerticalList().flingToBeginning(5);"));
    }
    catch(Exception e){
         e.printStackTrace();
    }
    
  • 错误:

    org.openqa.selenium.InvalidSelectorException: Could not parse expression `new UiScrollable(new UiSelector()).setAsVerticalList().flingToBeginning(5)`: Last method called on a UiScrollable object must return a UiObject object
    

有人帮忙解决一下

【问题讨论】:

    标签: appium ui-automation


    【解决方案1】:

    我推荐使用TouchAction在Android中进行滚动,例如:

    Dimension screenSize = driver.manage().window().getSize();
    TouchAction action = new TouchAction((PerformsTouchActions) driver);
    action.press(point(screenSize.width / 2, screenSize.height / 2))
       .waitAction()
       .moveTo(point(screenSize.width / 2, screenSize.height / 4))
       .release()
       .perform();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-24
      • 2020-11-12
      • 1970-01-01
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多