我UISearchBar
上有一个UIViewController
。
但是UISearchBar
默认没有辅助功能标识符,因此我尝试使用“用户定义运行时属性”来定义手动辅助功能标识符。
但在UITestCase
编写期间,我无法通过使用“用户定义运行时属性”来访问或识别UISearchBar
。但我无法使用标识符访问它。我总是不得不使用我不想使用的占位符文本,因为它会导致问题,同时具有“多语言”支持。
关于这个问题,我已经提到了堆栈溢出答案,但没有一个符合我的要求。
请帮助提供解决方案。 谢谢。
答案 0 :(得分:3)
在我使用用户定义运行时属性将accessibilityLabel
的{{1}}设置为UISearchBar
的应用程序中,如果查看应用程序的UI层次结构,您可以看到以下内容: / p>
MySearchBar
这应该可以让您了解如何找到您的搜索栏。首先搜索具有您设置到搜索栏的标识符的Attributes: Application, 0x604000198050, pid: 18393, {{0.0, 0.0}, {414.0, 736.0}}, label: 'MyApp'
Element subtree:
→Application, 0x604000198050, pid: 18393, {{0.0, 0.0}, {414.0, 736.0}}, label: 'MyApp'
Window, 0x6000001993d0, Main Window, {{0.0, 0.0}, {414.0, 736.0}}
Other, 0x604000199a50, traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}}
Other, 0x600000197aa0, traits: 8589934592, {{0.0, 20.0}, {414.0, 56.0}}, identifier: 'MySearchBar'
Image, 0x604000198390, traits: 8589934596, {{0.0, 0.0}, {414.0, 76.0}}
SearchField, 0x60000019a4e0, traits: 146031248384, {{8.0, 30.0}, {398.0, 36.0}}
类型的元素,然后找到other
类型的元素的子元素。
searchBar