ajc6432 ajc6432 - 3 months ago 21
iOS Question

Accessing nested UIElements in Xcode 7 UI Testing

I am having trouble locating XCUIElements on a screen for the app I am testing. I realize you can access a button for example via something like:


But the problem is sometimes, the component is not found. Like in a case where I have a Button in a cell in a UITableView. I try to make an XCUIElementQuery to find the button, and it is not there. I try to look for tables or tableviews or collection views and even though they are in the view controller, they are not found in UI Testing. The count of the returned array will be zero.

I attempted originally to record the test, but clicking the element I am trying to access did not work. Xcode detected it as an "Other Element" and when trying to tap during, playback the application does not advance.

Is there a high level way to access a component like a UIView high in the UI hierarchy to cascade down?


I didn't know this at the time, but what I was looking for was basically debugDescription:

Set a breakpoint when you hit the area you're trying to debug. Then

po print(app.debugDescription)

in the debug console. You will see the hierarchy then.