【发布时间】:2015-12-15 11:58:18
【问题描述】:
在我的应用程序中,有一个标签包含在一个简单的视图中。
该视图有一个点击识别器,它将触发一个功能(“为什么不使用按钮?”你可能会问..好吧,我们必须执行一些时髦的动画,这是我们最好的布局)。问题是我无法访问此视图来模拟点击它。
我可以使用app.staticText["Enter name..."] 访问标签,但如果我点击它(希望传播到父视图)。
记录我点击标签的会话将产生一个app.staticText["Enter name..."] 命令,但回放它会产生相同的错误。
我已尝试在情节提要中激活该视图的辅助功能平面并为其提供一个 ID,以便使用以下命令获取它:
app.windows.elementMatchingType(.Any, identifier: "MyView")
但是一旦检查了这个标志并且我运行了我的测试,应用程序就会进入一种循环,一遍又一遍地显示这条消息:
Find: Elements matching predicate '"MyView" IN identifiers'
此视图不在表格内,而是在主视图中。我怎样才能访问它?
编辑 1: 这是 app.DebugDescription() 的输出(感谢@Che 的建议):
Element subtree:
→Application 0x14e7e300: {{0.0, 0.0}, {320.0, 568.0}}, label: 'MyApp'
Window 0x14dbfef0: Main Window, {{0.0, 0.0}, {320.0, 568.0}}
Other 0x14dc0a40: traits: 8589934592, {{0.0, 0.0}, {320.0, 568.0}}
Other 0x14dc0ff0: traits: 8589934592
Other 0x14eb4f50: traits: 8589934592, {{0.0, 0.0}, {320.0, 568.0}}
Other 0x14eb53d0: traits: 8589934592
Button 0x14eb5940: traits: 8589934593, {{12.0, 26.0}, {30.0, 30.0}}, label: 'home hamburger'
Image 0x14eb5f00: traits: 8589934596, {{16.0, 30.0}, {22.0, 22.0}}, identifier: 'home_hamburger'
Other 0x14eb64c0: traits: 8589934592, {{0.0, 109.0}, {320.0, 459.0}}
Other 0x14eb6a20: traits: 8589934592, {{16.0, 167.0}, {288.0, 84.0}}
Image 0x14eb6f80: traits: 8589934596, {{59.0, 184.0}, {201.0, 50.0}}, identifier: 'main_logo'
Other 0x14eb4850: traits: 8589934592, {{16.0, 254.0}, {288.0, 60.0}}
StaticText 0x14eb79e0: traits: 8589934656, {{57.0, 264.0}, {160.0, 40.0}}, label: 'Enter name...'
Image 0x14eb7f90: traits: 8589934596, {{31.0, 275.0}, {18.0, 18.0}}, identifier: 'SearchIcon'
Other 0x14eb8530: traits: 8589934592, {{57.0, 274.0}, {2.0, 20.0}}
Other 0x14eb8ac0: traits: 8589934592, {{16.0, 262.0}, {288.0, 44.0}}
Image 0x14eb9060: traits: 8589934596, {{16.0, 262.0}, {288.0, 44.0}}
SearchField 0x14eb9610: traits: 146029151232, {{24.0, 270.0}, {272.0, 28.0}}
Other 0x14eb9bc0: traits: 8589934592
Other 0x14eba170: traits: 8589934592
Window 0x14eba730: {{0.0, 0.0}, {320.0, 568.0}}
StatusBar 0x14ebaca0: {{0.0, 0.0}, {320.0, 20.0}}
Other 0x14ebb220: {{0.0, 0.0}, {320.0, 20.0}}
Other 0x14ebb7b0: {{0.0, 0.0}, {320.0, 20.0}}
Other 0x14ebbd50: traits: 8388608, {{6.0, 0.0}, {35.0, 20.0}}, label: '3 of 5 bars, signal strength'
Other 0x14ebc330: traits: 8388608, {{44.0, 0.0}, {73.0, 20.0}}, label: 'vodafone UK network'
Other 0x14ebc8c0: traits: 8388608, {{122.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
Other 0x14ebce50: traits: 8389120, {{146.0, 0.0}, {32.0, 20.0}}, label: '11:34'
Other 0x14ebd3d0: traits: 8388608, {{282.0, 0.0}, {33.0, 20.0}}, label: '100% battery power, Charging'
Path to element:
→Application 0x14e7e300: {{0.0, 0.0}, {320.0, 568.0}}, label: 'MyApp'
Query chain:
→Find: Target Application 0x14ea2c00
Output: {
Application 0x14e7e300: {{0.0, 0.0}, {320.0, 568.0}}, label: 'MyApp'
}
【问题讨论】:
-
无障碍检查员告诉你什么? (Spotlight 搜索它,然后将鼠标悬停在模拟器中的元素上。)
-
我可以看到 textView 但看不到包含它的视图。我应该在检查器中搜索特定字段吗?一般来说,有什么方法可以像使用按钮、滑块、静态文本一样访问通用 UIView...
-
根据可访问性检查器,使用 app.staticText["MyLabel"] 我正在访问元素accessibilityRoleDescription=text 和accessibilityRole=AXStaticText,而不是textView 本身(它的accessibilityValue =
.
标签: ios xcode swift xcode-ui-testing