sebradloff
sebradloff

Reputation: 385

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:

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

Upvotes: 21

Views: 11574

Answers (3)

Patrick Ridd
Patrick Ridd

Reputation: 493

The thing that fixed it for me was to check √ the "Accessibility" box to enabled in Interface Builder.

enter image description here

If not working in IB try setting the the view's isAccessibilityElement property to true.

Hope that helps!

Upvotes: 0

Andres Wang
Andres Wang

Reputation: 295

I also encountered this problem in my UITableView. My cell has a containerView(UIView) which has subviews(TextView, UIButton...) and a collectionView with its cells.

I tried the accepted answer, but it didn't work.(UI Recorder or manual code didn't recognize my sub-elements). But sometimes I found the UITest suddenly recognized my sub-elements when I triggered something to refresh the table.

So right now I know if UITest can't find my subviews, I invoke tableView.reloadData to refresh the view, and then all the problem is gone.

Anyway, this is just a workaround, I hope Apple can fix it as soon as possible.

Upvotes: -1

quellish
quellish

Reputation: 21244

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.

Upvotes: 36

Related Questions