How to access back bar button item in universal way under UITests in Xcode? How to access back bar button item in universal way under UITests in Xcode? ios ios

How to access back bar button item in universal way under UITests in Xcode?


Generally the back button tends to be the first button element in the navigation bar

app.navigationBars.buttons.element(boundBy: 0).tap()


Based on Aaron Sofaers comment, you can also set the accessibilityIdentifier directly in Interface Builder.

enter image description here


Here's how you can do it in Swift 3:

app.navigationBars.buttons.element(boundBy: 0).tap()