Yag*_*iya 2 ios xcode-ui-testing
我有一个UISearchBar在我的一个UIViewController。但UISearchBar默认情况下没有可访问性标识符,因此我尝试使用“用户定义运行时属性”来定义手动可访问性标识符。
但是在UITestCase编写过程中,我无法UISearchBar使用“用户定义运行时属性”访问或识别。但我无法使用标识符访问它。我总是不得不使用我不想使用的占位符文本,因为它在支持“多语言”时会导致问题。
我已经参考了有关此问题的堆栈溢出答案,但没有一个符合我的要求。
请帮助提供解决方案。谢谢你。
在一个应用程序时,我设置了accessibilityLabel我的UISearchBar给MySearchBar使用用户定义运行时属性,如果你看一下应用程序的UI层次结构,你可以看到如下内容:
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具有您为搜索栏设置的标识符的 type 元素,然后找到该 type 元素的子元素searchBar。
let searchField = XCUIApplication().otherElements["MySearchBar"].searchFields.firstMatch
searchField.tap()
searchField.typeText("Hello")
| 归档时间: | 
 | 
| 查看次数: | 1563 次 | 
| 最近记录: |