Search code examples
xcode7ui-testingxcode-ui-testing

Extract information from XCUIElement


If I'm trying to write a generic test that isn't dependent on labels or other value-specific elements, how do I get that information? Like if I were to tap a tableview cell and need some information from there later. Like to identify which cell was tapped. How could I grab a label from it using an XCUIElement?


Solution

  • The information you can extract from XCUIElement is limited to those in the XCUIElementAttributes protocol. The most notable of these are, identifier, value, and title.

    You can set the identifier via -accessibilityIdentifier in your production code. The value property can be set from a couple of different paths, but it's usually the the active state of a control. For example, a picker's selected element.

    You can try using the Accessibility Inspector to see what's already set on your element and then using a query to find that element.