I have some buttons in my user interface that only display an image and no title. How can I access them during a UI Test? window.buttons["delete"].click()
doesn't find the button due to lack of title. And I cannot set the title because the image has some transparency.
You should set an accessibilityIdentifier
. This is a non-user-facing property which was designed to allow you to identify elements in your UI tests. It was introduced to stop people from abusing accessibilityLabel
, which people would previously use for identifying things in their tests, but which had an effect on the experience of Voiceover users, who hear the contents of accessibilityLabel
when they select an element.
// app code
let myButton: UIButton!
myButton.accessibilityIdentifier = "deleteButton"
// test code
let app = XCUIApplication()
let deleteButton = app.buttons["deleteButton"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With