How to access elements nested in UIStackView within MkMapView for UITests?
Asked Answered
P

1

6

I want to write UI tests for views inside a UIStackView thats inside a MKMapView. Here's a snippet of the MWE. I created a MKMapView added a UIStackView with two UIViews as subviews.

let map = MKMapView()
let view1 = UIView()
let view2 = UIView()
let stackView = UIStackView()
stackView.addArrangedSubview(view1)
stackView.addArrangedSubview(view2)
map.addSubview(stackView)
view.addSubview(map)

And I declared an accessibilityIdentifier for each element and set the isAccessibilityElement attribute to true.

view1.accessibilityIdentifier = "view1"
view2.accessibilityIdentifier = "view2"
stackView.accessibilityIdentifier = "stackView"
view1.isAccessibilityElement = true
view2.isAccessibilityElement = true
stackView.isAccessibilityElement = true

However, there are no subviews of the stack view visible in the app element subtree nor are they accessible. You can see the UIStackView with the identifier 'stackView' but not the UIViews.

Element subtree:
 →Application, 0x6000030080e0, pid: 11856, label: 'UITestWithStackView'
    Window (Main), 0x600003009500, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x600003009420, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x600003009340, {{0.0, 0.0}, {414.0, 896.0}}
          Other, 0x600003009260, {{0.0, 0.0}, {414.0, 896.0}}
            Other, 0x600003009180, {{0.0, 0.0}, {414.0, 896.0}}
              Other, 0x6000030090a0, {{7.0, 348.0}, {400.0, 200.0}}, identifier: 'stackView'
              Other, 0x600003008fc0, {{0.0, 0.0}, {414.0, 896.0}}
                Map, 0x600003008ee0, {{0.0, 0.0}, {414.0, 896.0}}
                Other, 0x600003008e00, {{0.0, 0.0}, {414.0, 896.0}}
              Link, 0x600003008d20, {{375.4, 841.3}, {28.6, 10.7}}, label: 'Legal'
    Window, 0x600003008c40, {{0.0, 0.0}, {414.0, 896.0}}
      Other, 0x600003008b60, {{0.0, 0.0}, {414.0, 896.0}}
        Other, 0x600003008a80, {{0.0, 0.0}, {414.0, 896.0}}

Are there any known workarounds for this behavior?

Pori answered 10/12, 2019 at 8:1 Comment(1)
I'm also experiencing this strange issue. Very frustrating.Jezabella
C
0

Had the same issue with nested stack view. In my case it was a stackView with label that was nested in two other stacks.I needed to access labels. Using AccessiblityElements helped to access elements in the lower stack.

rootStackView.accesibilityElements[nestedElementsThatNeedToMakeAccessible]

If I understood your case correctly, try this

stackView.accessibilityElements[view1, view2]
map.accessibilityElements[stackView]
Counterwork answered 12/5, 2021 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.