如何遍历 ui table 中不同类型的元素 swift

How to iterate through ui table elements of different types in swift

使用 XCUITest,有没有办法遍历 swift 中 table 的子集,其中包含 'Cells' 和 'Other'?我知道我可以做 table.otherElements 或 table.cells 来分别访问每个元素,但是有没有办法获取 table 的所有元素,无论类型是单元格还是其他, 然后遍历那些?

children 和 descendants 查询要求您指定一个类型,因此使用它我还必须指定 Other 或 Cells。

我可以访问 table 元素,但我希望仅遍历前 8 个左右的元素以验证每个 other/cell 元素中的内容。

Type 枚举为您提供了一个 .any 选项,可以匹配任何元素。

XCUIApplication().tables.children(matching: .any)