在swift中查找多种类型的XCUIElement



我想找到两个xcuielement,在下面的代码中找到它们没有问题。

func cells(_ text:String) {
app.cells.element(withLabelContaining: text).firstMatch
}
func text(_ text:String) {
app.staticText.element(withLabelContaining: text).firstMatch
}

然而,我想找到一种方法,只是使用一个查询寻找多种类型的XCUIElement,我怎么能做到这一点?我检查了文档,但我找不到任何解决方案

不同类型的XCUIElement

假设:

let app = XCUIApplication()

app.staticText实际上是

的快捷方式
app.windows.descendants(matching: XCUIElement.ElementType.staticText)

因此类推,我们可以这样做:

let typesToBeFound = [XCUIElement.ElementType.cell.rawValue, 
XCUIElement.ElementType.staticText.rawValue]
let predicateFormat = "elementType == %lu OR elementType == %lu"
let predicate = NSPredicate(format: predicateFormat, argumentArray: typesToBeFound)
let result = app.windows.descendants(matching: XCUIElement.ElementType.any).matching(predicate)

最新更新