Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40196

iOS UITests - What purpose XCUIElements identifier serves

While woking on iOS UITests, I found XCUIElement has a property, identifier, which was confronted from XCUIElementAttributes. When I debug, I found this is a real-only property and always contains empty string. Can anyone explain what purpose this property serves? I am unable to get any distinguishing property between two XCUIElement

I cannot change the identifier, its immutable.

enter image description here

Upvotes: 0

Views: 720

Answers (1)

Oletha
Oletha

Reputation: 7649

The identifier property of an XCUIElement is the same as the accessibility identifier of the UIView it represents.

// app code
let someButton: UIButton!
someButton.accessibilityIdentifier = "myIdentifer"

// test code
let button = XCUIApplication().buttons["myIdentifier"] // get XCUIElement for the button
print(button.identifier) // => "myIdentifier"

If the identifier is empty, this is because the accessibilityIdentifier property has not been set on the view.

Upvotes: 1

Related Questions