So I'm adding a child view to my view programatically, 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.
Any idea how to 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
来源:https://stackoverflow.com/questions/36776383/xcode-ui-tests-cant-find-views-that-are-added-programatically