使用UIAutomator2无法向后滚动

时间:2019-12-06 08:07:10

标签: appium ui-automation

我正在尝试使用以下代码片段向后滚动,但会引发错误

  • 代码段

    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
    

有人请帮忙

1 个答案:

答案 0 :(得分:0)

我建议使用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();