【问题标题】:How to scroll screen in android native app having recyclerview using appium如何使用appium在具有recyclerview的android本机应用程序中滚动屏幕
【发布时间】:2020-02-20 22:45:36
【问题描述】:

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

【问题讨论】:

  • 您可以使用动作指定或更改坐标吗?它应该运作良好。
  • @john,我尝试了 [this] (discuss.appium.io/t/…) 中给出的代码。我刚刚使用 TouchAction 类替换了 drive.swipe() 。但我仍然无法滚动。如果可以的话,请给我一些示例代码,你到底想告诉我什么。
  • swipe 已被弃用一段时间,除非您使用的是旧版 java-client

标签: java appium-android


【解决方案1】:

请试试这个。我认为您的 UiScrollable 中存在一些问题..

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

【讨论】:

  • 我试过你的代码,但我仍然无法滚动页面,直到我看到我需要的元素
  • 这个滚动条实际上​​就像它向下滚动一样,如果找不到元素,然后它会随机向上或向下滚动。所以没有具体的顺序。但它会双向滚动,直到找不到元素。它在我的应用程序中完美运行。
  • 是的,你是对的。它随机上下滚动,但屏幕上只有轻微的移动。
  • 屏幕上下随机滚动,一段时间后出现以下错误。 org.openqa.selenium.NoSuchElementException:使用给定的搜索参数无法在页面上找到元素。
  • 我认为问题可能出在元素定位器中。您可能提到了元素的错误值。
【解决方案2】:

@Sammar Ahmad,是的,你是对的。我使用了错误的元素。在使用坐标后,我不断尝试并最终工作。代码如下所示。在主页类中创建 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);

【讨论】:

    【解决方案3】:
    MobileElement listItem=(MobileElement)driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"<Mention your element text value here>\"))"));
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-20
      • 1970-01-01
      • 2019-12-10
      • 1970-01-01
      • 2014-06-13
      • 2015-11-17
      • 2019-02-14
      • 2018-09-04
      相关资源
      最近更新 更多