Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode UI Tests can't find views that are added programmatically

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?

like image 535
Mr.Me Avatar asked Dec 14 '22 06:12

Mr.Me


1 Answers

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

like image 176
Tomas Camin Avatar answered Dec 26 '22 10:12

Tomas Camin