首页 > 解决方案 > 如何在 attributesPlaceholder 中设置可访问性标识符

问题描述

我有给定的一段代码

textField.attributedPlaceholder = NSAttributedString(string: Strings.test,
                                                             attributes: [NSAttributedString.Key.foregroundColor: ColorTheme.test])

如何在AttributePlaceholder 中设置可访问性标识符,以便以后可以在UITest 中使用包含字符串?

标签: swiftxctest

解决方案


您需要为您的文本字段提供可访问性标识符。然后您可以通过属性获取占位符文本。

let textField = XCUIApplication().textFields["textFieldIdentifier"]
let placeholderText = textField.placeholderValue

推荐阅读