gpt4 book ai didi

ios - 如何获取 Appium 中元素的子元素列表?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:37:40 25 4
gpt4 key购买 nike

我正在通过 Appium 使用 native iOS 应用程序。

我有以下结构:

UIAApplication ->
UIAWindow ->
UIATextBox
UIALabel
UIAWindow ->
SomethingElse

我找到了获取第一个 UIAWindow 的方法,我想获取该窗口中所有元素的列表。我该怎么做?

我想从第一个 UIAWindow 而不是 SomethingElse 元素获取 UIATextBox 和 UIAlabel。

一般情况下如何列出子元素?

  @Test
public void testListWindows() {
List<MobileElement> windows = driver.findElementsByClassName("UIAWindow");
List<MobileElement> elements = windows.get(0).?????
}

最佳答案

你快到了。当您想要的是第一个 UIAWindow 的所有元素的列表时,您所拥有的是为您提供所有 UIAWindows 的列表。我建议使用带通配符的 Xpath。

这将为您提供第一个 UIAWindow 的直接子元素的每个元素:

List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]/*");

这将为您提供第一个 UIAWindow 的每个 child 、子 child 和子子 child 等:

List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]//*");

额外提示:如果您要为 iOS 实现自动化,我认为这意味着您可以访问 OS X,您可以在其中安装 Appium dot 应用程序并使用检查器。检查器是一个很好的工具,可以在将 xpath 查询放入您的代码之前对其进行测试。

关于ios - 如何获取 Appium 中元素的子元素列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34255688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com