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

倖福魔咒の 提交于 2019-11-28 09:15:11

问题


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 ?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!