Unable to tap SwiftUI menu with XCUITest (ios15)

I have a SwiftUI menu

Menu{
 ....
}, label : {
 Image(...).accessibility(identifier: "cardMenu")
}

I used to be able to bring up the menu (before upgrading to xcode 13 (ios15)) like this

let app = XCUIApplication() 
app.launch()
app.buttons["cardMenu"].tap()

But now i am unable to see the identifier in app.buttons. Can't seem to find the identifier anymore. I've tried looking for the identifier in the other app fields and changing to use text instead of identifer. No luck. These tests used to work prior to the upgrade.

Any help would be appreciated

Post not yet marked as solved Up vote post of jsh22 Down vote post of jsh22
2.2k views

Replies

You can use Accessibility Inspector to find the Identifier of a view.

  1. Plug in your phone to your Mac and run Accessibility Inspector
  2. Select your device from the devices Pop-Up menu. Make sure your application is launched on your device.
  3. Select the "Target an Element" button in Accessibility Inspector.
  4. On your phone, tap the button you wish to inspect using your finger.
  5. You should see information about that button in Accessibility Inspector, including its identifier.

XCUIApplication should be able to tap any button via its identifier or label.

  • Tapping SwiftUI menu has been broken for quite a while now. Nothing works (coordinates, identifier, etc.)

Add a Comment

Been seeing this a while with iOS 17 update. The button exists with the identifier but .tap() does nothing.

Instead of using buttons, use images:

app.images["cardMenu"].tap()