如何使用 appium 在具有 recyclerview 的 android 本机应用程序中滚动屏幕

How to scroll screen in android native app having recyclerview using appium

我正在尝试自动化使用 recyclerview 构建的应用程序。总共有 10 个图块,在一个屏幕中,第一个四个图块是可见的,要获得其他图块,我需要向上移动屏幕。我试图通过查找坐标和“(AndroidElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().resourceIdMatches(\".*id/type_text\")).setMaxSearchSwipes(5) 来移动屏幕。 scrollIntoView("new UiSelector().text(\"" + text + "\"))"))" 这个但是屏幕有轻微的移动,无法获取剩余的图块。有没有办法滚动到屏幕底部这样我也可以获得最后一块瓷砖。

请试试这个。我觉得你的 UiScrollable 有问题..

MobileElement listItem=(MobileElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()"
                  + ".scrollable(true)).scrollIntoView("
                  + "new UiSelector().text(\"<Mention your element text value here>\"))"));

@Sammar Ahmad,是的,你是对的。我使用了错误的元素。我不断尝试并在使用 co-ordinates.Code 后终于成功了,如下所示。在主页 class 中创建了 scroll() 并在我的测试 class

中调用了相同的方法
public void scroll(int x, int y) {
    int startY = (int) (driver.manage().window().getSize().getHeight() * 0.90);
    int endY = (int) (driver.manage().window().getSize().getHeight() * 0.10);
    TouchAction action = new TouchAction(driver);
    action.press(point(x, startY)).waitAction(waitOptions(ofSeconds(3))).moveTo(point(x, endY)).release().perform();
}

MobileElement startElement = (MobileElement) driver.findElementById("mention parent element here");
Point location = startElement.getLocation();
    homepage.scroll(location.x,location.y);
MobileElement listItem=(MobileElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"<Mention your element text value here>\"))"));

您可以像这样修改@sammar 的代码以滚动到该元素。