Appium - 获取 UiScrollable 中的所有项目(包括不可见)

发布于 2025-01-17 06:43:18 字数 706 浏览 6 评论 0原文

我需要使用 Appium 验证列表中(在 UiScrollable 内)所有 项目的文本。 以下方法对我不起作用:

  1. driver.findElements(MobileBy.id("com.author.app:id/title")) - 仅返回当前可见的元素(不执行滚动直到列表末尾)

  2. 我知道即使一个项目不可见,也可以验证该项目(在整个列表中执行滚动)

    WebElement element =  driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable("
                    + "new UiSelector().scrollable(true)).scrollIntoView("
                    + "new UiSelector().textContains(\"MyText\"));"))

但这只是针对一个预定义的项目。

  1. 我知道有一些方法,例如 getChildByText/getChildByDescription ,但它们需要一些文本(当我需要获取所有项目时)。

那么有没有办法获取所有列表项(包括滚动到当前不可见的项目)?

I need to verify text for all items in list (inside UiScrollable) using Appium.
Following approaches are not working for me:

  1. driver.findElements(MobileBy.id("com.author.app:id/title")) - returns only currently visible elements (do not perform scroll till the end of list)

  2. I know the way for verifying one item even when it's not visible (scroll is performed through the whole list)

    WebElement element =  driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable("
                    + "new UiSelector().scrollable(true)).scrollIntoView("
                    + "new UiSelector().textContains(\"MyText\"));"))

But it's just for one predefined item.

  1. I know there are some methods like getChildByText/getChildByDescription but they require some text (when I need to get all items).

So is there any way to get all list items (including scroll to items that are not currently visible)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2025-01-24 06:43:18

有两种方法可以做到这一点。它将根据您的元素可见性向上或向下滚动

    ThreadLocalDriver.getTLDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+element+"\").instance(0))"));

    ThreadLocalDriver.getTLDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textMatches(\"" + element + "\").instance(0))"));

There are two ways to do it . It will scroll up or down depending on your elements visibility

    ThreadLocalDriver.getTLDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+element+"\").instance(0))"));

    ThreadLocalDriver.getTLDriver().findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textMatches(\"" + element + "\").instance(0))"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文