1

I would like to locate two XCUIElements and no problem to find them in following code.

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

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

However, I would like to find a way to just use one query to look for multiple type of XCUIElement, how can I do it? I check the doc but I cannot find any solution for it

different type of XCUIElement

jacobcan118
  • 7,797
  • 12
  • 50
  • 95

1 Answers1

1

Assuming:

let app = XCUIApplication()

the app.staticText is effectively a shortcut for

app.windows.descendants(matching: XCUIElement.ElementType.staticText)

Hence by analogy we can do this:

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)
Kamil.S
  • 5,205
  • 2
  • 22
  • 51