Xcode UI测试找不到以编程方式添加的视图 [英] Xcode UI Tests can't find views that are added programmatically

查看:70
本文介绍了Xcode UI测试找不到以编程方式添加的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以编程方式将子视图添加到我的视图中,当我将所有可访问性参数附加到该视图时:

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];

但是当我这样查询UI时:

But when I query the UI like this:

 let app = XCUIApplication()
 app.staticTexts["label"]

测试失败,因为它找不到视图.

The test fails because it couldn't find the view.

我该如何处理,如何使可动态添加的视图可用于UI测试?

How do I deal with this, how to make dynamically added views available for UI Testing?

推荐答案

您需要确保标签视图(UIEditText?)的容器视图未将isAccessibilityElement设置为YES.如果这样做,它将隐藏其子视图(您的标签)的可访问性.

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).

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆