簡體   English   中英

如何使用 appium 在具有 recyclerview 的 android 本機應用程序中滾動屏幕

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

我正在嘗試自動化使用 recyclerview 構建的應用程序。 總共有 10 個圖塊,在一個屏幕中,第一個 4 個圖塊是可見的,要獲得其他圖塊,我需要向上移動屏幕。 我試圖通過查找坐標和“(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,是的,你是對的。 我使用了錯誤的元素。 在使用坐標后,我不斷嘗試並最終工作。代碼如下所示。 在主頁 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 的代碼以滾動到元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM