简体   繁体   中英

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.

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM