sebradloff sebradloff - 1 year ago 181
iOS Question

UI Testing XCode 7- can't access element within subview

I'm trying to access an element within a subview and I'm finding it impossible to do so.

The hierarchy being:

View Controller:

  • View

    • tempView

    • userEnterView

      • zipCodeEntered

I want to access the zipCodeEntered text field. I have an accessibility label on it named "zipCodeEntered".

When I try and record the automation, it only register the superview "userEnterView" and not the actual text field which I can tap into.

I print "app.otherElements[SUPER_VIEW_NAME].debugDescription" to see what elements are in that hierarchy and it prints none.

Any ideas as to why I can not access these elements/how I can access them?
enter image description here

Answer Source

The subviews are not accessible because the parent view is not a container view. From the section Making Your iOS App Accessible from the Accessibility Programming Guide:

From the perspective of accessibility, a custom view is either an individual view or a container view. An individual view does not contain any other views that need to be accessible.

A container view, on the other hand, contains other elements with which users can interact.

To make the subviews accessible the parent view should tell UIAccessibility that it is an accessibility container by returning NO from -isAccessibilityElement and implementing the methods of the UIAccessibilityContainer protocol.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download