Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI Testing with Xcode: How to find a button that has no title?

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.

like image 781
Wizard of Kneup Avatar asked Jun 04 '17 16:06

Wizard of Kneup


1 Answers

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"]
like image 88
Oletha Avatar answered Dec 30 '22 16:12

Oletha