accessibilityIdentifier not working the same starting with iOS 15

The app on which I am working has it's ui tested using Appium. Because of this, I set accessibility identifiers on views.

struct RootView: View {
    var body: some View {
        VStack {
            Text("some text")
            Text("more text")
        }
        // wrapper 1
        .accessibilityElement(children: .contain)
        .accessibilityIdentifier("ID 1111111111111")
        // wrapper 2
        .accessibilityElement(children: .contain)
        .accessibilityIdentifier("ID 2222222222222")
    }
}

(the code is oversimplified to ease the understanding of the problem)

Running the code above on iOS 14 would output this on Appium Inspector when inspecting the views:

 <XCUIElementTypeOther type="XCUIElementTypeOther" name="ID 2222222222222" enabled="true" visible="true" accessible="false" x="157" y="408" width="76" height="41" index="0">
              <XCUIElementTypeOther type="XCUIElementTypeOther" name="ID 1111111111111" enabled="true" visible="true" accessible="false" x="157" y="408" width="76" height="41" index="0">
                <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="some text" name="some text" label="some text" enabled="true" visible="true" accessible="true" x="157" y="408" width="76" height="21" index="0"/>
                <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="more text" name="more text" label="more text" enabled="true" visible="true" accessible="true" x="159" y="428" width="73" height="21" index="1"/>
              </XCUIElementTypeOther>
            </XCUIElementTypeOther>

So each group of accessibilityElement and accessibilityIdentifier would create a XCUIElementTypeOther with the same name property as the id set by accessibilityIdentifier.

With iOS 15/16 these are not working anymore, here is the output on Appium Inspector when inspecting the views:

<XCUIElementTypeOther type="XCUIElementTypeOther" name="ID 2222222222222" enabled="true" visible="true" accessible="false" x="157" y="408" width="76" height="41" index="0">
                <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="some text" name="some text" label="some text" enabled="true" visible="true" accessible="true" x="157" y="408" width="76" height="21" index="0"/>
                <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="more text" name="more text" label="more text" enabled="true" visible="true" accessible="true" x="158" y="428" width="74" height="21" index="1"/>
              </XCUIElementTypeOther>

It looks like the first group of accessibilityElement and accessibilityIdentifier is no longer generating an XCUIElementTypeOther.

Is there a way to have the same output of iOS 14 on iOS 15/16?

Hi thanks for posting this.

This should be an expected behavior, and looks like a bug on iOS 14: Basically if you apply accessibilityElement(children:) modifier to the same view (VStack) for example, the latter should override the former. This is also the case for every other SwiftUI modifiers.

If you want a separate container out of this, you could wrap it around another VStack and apply the wrapper2 on the outer VStack.

@ericliang I tried the following, as you suggested, but the outcome is the same as with the initial code for iOS 15/16;

     VStack {
      VStack {
        Text("some text")
        Text("more text")
      }
      // wrapper 1
      .accessibilityElement(children: .contain)
      .accessibilityIdentifier("ID 1111111111111")
    }
    // wrapper 2
    .accessibilityElement(children: .contain)
    .accessibilityIdentifier("ID 2222222222222")
accessibilityIdentifier not working the same starting with iOS 15
 
 
Q