Vish Vish - 5 months ago 65
iOS Question

Xcode UI Testing (Objective C): find element by Accessibility Label

My app under test has an element (a

UIAStaticText
) which has accessibility enabled (with the accessibility-label "Progress").

Accessing this element using Swift is easy and well-documented. But my app's source is in Objective C.

How do I access this element using Xcode UI Testing and Objective C?

Answer

I found one way to do this. This does get me the correct element - but I feel there has to be a simpler answer that does not rely on me knowing the element's type (staticText).

If anyone has a better answer, you are welcome to contribute.

XCUIElement *progressTextByAccessibility = [[app staticTexts] elementMatchingType:XCUIElementTypeStaticText identifier:@"Progress"];
Comments