I'm adding a child view to my view programmatically, and when I do I attach all accessibility params to it:
[labelView setAccessibilityLabel:@"label"];
[labelView setIsAccessibilityElement:YES];
[labelView setUserInteractionEnabled:YES];
But when I query the UI like this:
let app = XCUIApplication()
app.staticTexts["label"]
The test fails because it couldn't find the view.
How do I deal with this, how to make dynamically added views available for UI Testing?
You need to make sure that the container view of your label view (UIEditText?) doesn't have isAccessibilityElement
set to YES. If it does it will hide the accessibility of its subviews (your label).
Check Make the Contents of Custom Container Views Accessible in the Accessibility Programming Guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With