ios - 元素不保留其 Storyboard 可访问性标识符或运行时类型

标签 ios swift storyboard xcode-ui-testing

我有一个自动化的 UI 测试,通过使用 XCUIElement 查询来确保页面显示正确的元素

let instructionLabelID = "UIA_HelpViewController_InstructionLabel"
let callViewID = "UIA_HelpViewController_CallTextView"

var instructionLabel: XCUIElement { return app.staticTexts[instructionLabelID] }
var instructions: String { return instructionLabel.label }

var callLabel: XCUIElement { return app.textViews[callViewID] }
var callText: String { return callLabel.value as! String }

这是对应的storyboard

storyboard

由于未找到突出显示的 View ,测试失败,即使我们可以在 Storyboard中看到它的标识符是正确的。通过断点,我可以在运行时检查所有元素,结果如下

bp

正如我们所见,第一个元素是正确的,因为它位于 Other(它的容器 View )下,具有 StaticText 类型,并具有其标识符。然而,第二个元素似乎被合并到它的容器中而不是它的子元素。两个容器都未选中“启用辅助功能”选项。我该如何解决这个问题?

最佳答案

看起来您已将 TextView 设置为在容器上具有 accessibilityTraits = .notEnabled 而不是设置 isAccessibilityElement = false。

如果可能,请尝试在代码中而不是 Storyboard中设置这些属性,因为它可以为您提供更多控制 - Storyboard值很容易被覆盖,但如果您在代码中设置它,您可以控制何时设置标识符并覆盖它们如果有任何干扰。

关于ios - 元素不保留其 Storyboard 可访问性标识符或运行时类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52415900/

相关文章:

arrays - 在 for-in 循环中更改数组的大小

ios - 自定义 UIStoryboardSegue - UIViewController 支持的InterfaceOrientations 从不调用

ios - 如何使用自动布局更改标签位置

javascript - 如何重定向到 Safari 中的 ios 设置在 ios9 中使用 javascript

ios - 在矩形的每条边上创建圆

ios - 找到运动方向?

ios - AWS batchGetItem NSInvalidArgumentException JSONKeyPathsByPropertyKey:无法识别的选择器

ios - 这种类型的 View 呈现样式的名称是什么?

swift - 返回用户输入的数据类型

ios - 无法在 Xcode Storyboard 中调整 UITextField 的大小