accessibilityIdentifier of buttons in swipeActions are not getting read by [Xcode]Accessibility Inspector Tool

I have a swiftUI view that lists items. They have trailing swipe actions. I have given accessibilityIdentifiers to the button in the swipe menu. But the Xcode tool: Accessibility Inspector, does not get them first time.

Here is my view:

import SwiftUI

struct Person: Identifiable {
     let id = UUID()
     var name: String
     var phoneNumber: String
 }

var staff = [
    Person(name: "Harry Potter", phoneNumber: "(408) 555-4301"),
    Person(name: "Ronald Weasley", phoneNumber: "(919) 555-2481")
]

struct ContentView: View {
    var body: some View {
        List {
            ForEach(staff) { person in
                Cell(title: person.name)
            }
        }
    }
}

struct Cell: View {
    
    var title: String
    
    var body: some View {
        Text(title)
            .swipeActions {
                swipeMenu
            }
    }
    
    @ViewBuilder var swipeMenu: some View {
        Button {
        } label: {
            Label("Logout", systemImage: "logout")
        }
        .tint(.blue)
        .accessibilityIdentifier("person-logout")
        
        Button {
        } label: {
            Label("Edit", systemImage: "edit")
        }
        .tint(.green)
        .accessibilityIdentifier("person-edit")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Steps:

  1. Open the app.

  1. Swipe first row. "Edit" and "Logout" actions become visible.

  1. Launch the Accessibility inspector.

  2. Inspect the UI. The Identifiers for "Edit" and "Logout" button are not captured by the inspector.

  1. Swipe the row to hide the actions.

  2. Now swipe the row again to view the actions.

  3. Inspect the UI elements. This time the Accessibility inspector is able to capture the identifiers.

Why is this happening? How do we get the Accessibility Inspector to capture the identifiers the first time?

Replies

Hi, could you please file a Feedback Assistant report with these details so we can take a closer look? Thank you!