为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

墨色风雨 2023-12-13 10:43:33
我正在尝试自动化使用 recyclerview 构建的应用程序。总共有 10 个图块,在一个屏幕中,第 4 个图块将可见,要获得其他图块,我需要向上移动屏幕。我尝试通过查找坐标和 "(AndroidElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().resourceIdMatches(\".*id/type_text\")).setMaxSearchSwipes(5 ).scrollIntoView("new UiSelector().text(\"" + text + "\"))"))" 但是屏幕上有轻微的移动,无法获取剩余的图块。有什么办法可以滚动到屏幕底部,这样我也可以获得最后一个图块。
查看完整描述

3 回答

?
慕运维8079593

TA贡献1876条经验 获得超5个赞

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

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


查看完整回答
反对 回复 2023-12-13
?
动漫人物

TA贡献1815条经验 获得超10个赞

请尝试这个。我认为你的 UiScrollable 有问题..

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



查看完整回答
反对 回复 2023-12-13
?
HUX布斯

TA贡献1876条经验 获得超6个赞

我使用了错误的元素。我不断尝试,终于在使用坐标后成功了。代码如下所示。在主页类中创建了scroll(),并从我的测试类中调用了相同的内容


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


查看完整回答
反对 回复 2023-12-13
  • 3 回答
  • 0 关注
  • 73 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信