XCTest: Is there a way to find a view of any type by ID in UI tests?
Asked Answered
W

1

5

In XCTest there's a way to get all UI elements by type, and then filter by accessibilityIdentifier like:

app.buttons[someID]

But what if I don't know the type of the view? If I'm looking for a UIView, I can write:

app.otherElements[someID]

but this excludes UIButton views.

I can implement this by calling all the methods in succession (staticTexts, textViews, buttons, otherElements etc.), but something tells me it's not great in performance, because the list of types is huge.

Is there a generic method?

Wirewove answered 14/4, 2019 at 17:40 Comment(0)
T
19

You can use descendants(matching:) to look for views of any type.

let app = XCUIApplication()
let element = app.descendants(matching: .any)["someID"]
Trixie answered 15/4, 2019 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.