Reputation: 40196
While iOS UITesting, how can I distinguish between two different XCUIElement
?
For example I have two different UIButton
with same label string "Button". How to check they are different? Do XCUIElement
provides ID or any distinct property?
Upvotes: 1
Views: 374
Reputation: 7649
Add an accessibilityIdentifier
to each button in your app's code and access each button by its identifier in your tests to tell them apart. Accessibility identifiers are not user-facing, even to Accessibility users, so this will not affect your user experience.
// app code
buttonA.accessibilityIdentifier = "buttonA"
buttonB.accessibilityIdentifier = "buttonB"
// test code
let app = XCUIApplication()
let buttonA = app.buttons["buttonA"]
let buttonB = app.buttons["buttonB"]
Upvotes: 2