我正在尝试为我的应用编写UI测试。我有一个弹出窗口,它是一个模态呈现的视图控制器,上面有一个UITableView。 tableview包含2个可单击的单元格,这两个单元格都会关闭视图控制器。问题是当弹出这个弹出窗口时,它会显示为"其他元素"在我的元素树中而不是视图控制器。我可以找到otherElements[@"PopOverViewController"]
元素,但我无法点击控制器上的单元格,因为它不知道它们是什么。
→Other 0x7fc778039540: traits: 8589934592, {{32.0, 155.5}, {311.0, 356.0}}, label: 'PopOverViewController'
如何访问此元素并单击此视图控制器上的按钮?
由于
修改
这是PopOverViewController显示时的输出
Image 0x7fc26378c270: traits: 8589934596
Image 0x7fc263784310: traits: 8589934596, {{0.0, 0.0}, {375.0, 64.0}}
Button 0x7fc263786ff0: traits: 8724152321, {{8.0, 26.0}, {110.0, 30.0}}, label: '*****'
Button 0x7fc26378d480: traits: 8724152321, {{8.0, 36.5}, {11.0, 11.0}}, label: '*****'
StaticText 0x7fc263794620: traits: 8589934656
StaticText 0x7fc2637817d0: traits: 8590000192
NavigationBar 0x7fc263788140: traits: 35192962023424, {{0.0, 20.0}, {375.0, 44.0}}, identifier: '*****'
StaticText 0x7fc263793090: traits: 8589934656, {{146.5, 70.5}, {82.0, 22.0}}, label: '*****'
Button 0x7fc26378ea40: traits: 8589934593, {{67.5, 104.5}, {240.0, 35.0}}, label: '*****'
StaticText 0x7fc26378de50: traits: 8589934656, {{86.0, 155.5}, {203.5, 38.5}}, label: '*****'
Other 0x7fc263795f30: traits: 8589934592, {{67.5, 54.0}, {240.0, 168.0}}
Other 0x7fc26379b470: traits: 8589934592
Other 0x7fc26379a570: traits: 8589934592, {{0.0, 64.0}, {375.0, 148.0}}
Other 0x7fc26378f9c0: traits: 8589934592, {{0.0, 216.0}, {375.0, 407.0}}
StaticText 0x7fc26379be90: traits: 8589934656, {{90.0, 232.0}, {53.5, 20.5}}, label: '*****'
StaticText 0x7fc26379c4f0: traits: 8589934656, {{90.0, 250.0}, {114.0, 19.5}}, label: '*****'
StaticText 0x7fc26379cd60: traits: 8589934656, {{90.0, 289.0}, {57.0, 18.0}}, label: '*****'
Cell 0x7fc2637934c0: traits: 8589934592, {{0.0, 216.0}, {375.0, 123.0}}
StaticText 0x7fc26379dc10: traits: 8589934656, {{90.0, 355.0}, {52.5, 20.5}}, label: '*****'
StaticText 0x7fc26379e330: traits: 8589934656, {{90.0, 373.0}, {98.0, 19.5}}, label: '*****'
StaticText 0x7fc26379ea80: traits: 8589934656, {{90.0, 412.0}, {57.0, 18.0}}, label: '*****'
Cell 0x7fc26379d490: traits: 8589934592, {{0.0, 339.0}, {375.0, 123.0}}
StaticText 0x7fc26379f970: traits: 8589934656, {{90.0, 478.0}, {95.0, 20.5}}, label: '*****'
StaticText 0x7fc2637a00b0: traits: 8589934656, {{90.0, 496.0}, {129.5, 19.5}}, label: '*****'
StaticText 0x7fc2637a0800: traits: 8589934656, {{90.0, 535.0}, {57.0, 18.0}}, label: '*****'
Cell 0x7fc26379f1f0: traits: 8589934592, {{0.0, 462.0}, {375.0, 123.0}}
Table 0x7fc2637901b0: traits: 35192962023424, {{0.0, 64.0}, {375.0, 559.0}}
Button 0x7fc2637a0ff0: traits: 8589934593, {{0.0, 623.0}, {375.0, 44.0}}, label: '*****'
Other 0x7fc2637a1710: traits: 8589934592
Other 0x7fc263796ea0: traits: 8589934592, {{0.0, 64.0}, {375.0, 603.0}}
Other 0x7fc263799490: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc263791ac0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc26376a060: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Image 0x7fc2637a26a0: traits: 4, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a2de0: {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a3500: traits: 8589934592, {{32.0, 155.5}, {311.0, 356.0}}, label: 'PopOverViewController'
Other 0x7fc2637a1f50: {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc263782e40: {{0.0, 0.0}, {375.0, 667.0}}
Window 0x7fc263112950: Main Window, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a4cc0: traits: 8589934592
Other 0x7fc2637a44d0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Window 0x7fc2637a3d50: {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a6340: {{0.0, 0.0}, {375.0, 20.0}}
Other 0x7fc2637a7210: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
Other 0x7fc2637a7960: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
Other 0x7fc2637a80e0: traits: 8389120, {{165.0, 0.0}, {48.0, 20.0}}, label: '1:29 PM'
Other 0x7fc2637a8850: traits: 8388608, {{345.0, 0.0}, {25.0, 20.0}}, label: '-100% battery power'
Other 0x7fc2637a6a90: {{0.0, 0.0}, {375.0, 20.0}}
StatusBar 0x7fc2637a5bd0: {{0.0, 0.0}, {375.0, 20.0}}
Window 0x7fc2637a5450: {{0.0, 0.0}, {375.0, 667.0}}
我可以看到PopOverViewController,但没有任何文本或单元格(文本被消隐,但来自呈现视图控制器,而不是弹出视图控制器上的内容)
修改
如果我运行[app.otherElements[@"PopOverViewController"] descendantsMatchingType:XCUIElementTypeAny]
,我会看到输出:
Other 0x7fc263795f30: traits: 8589934592, {{67.5, 54.0}, {240.0, 168.0}}
Other 0x7fc26379b470: traits: 8589934592
Other 0x7fc26379a570: traits: 8589934592, {{0.0, 64.0}, {375.0, 148.0}}
Other 0x7fc26378f9c0: traits: 8589934592, {{0.0, 216.0}, {375.0, 407.0}}
Other 0x7fc2637a1710: traits: 8589934592
Other 0x7fc263796ea0: traits: 8589934592, {{0.0, 64.0}, {375.0, 603.0}}
Other 0x7fc263799490: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc263791ac0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc26376a060: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a2de0: {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a3500: traits: 8589934592, {{32.0, 155.5}, {311.0, 356.0}}, label: 'PopOverViewController'
Other 0x7fc2637a1f50: {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc263782e40: {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a4cc0: traits: 8589934592
Other 0x7fc2637a44d0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc2637a6340: {{0.0, 0.0}, {375.0, 20.0}}
Other 0x7fc2637a7210: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}}
Other 0x7fc2637a7960: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID
Other 0x7fc2637a80e0: traits: 8389120, {{165.0, 0.0}, {48.0, 20.0}}, label: '1:29 PM'
Other 0x7fc2637a8850: traits: 8388608, {{345.0, 0.0}, {25.0, 20.0}}, label: '-100% battery power'
Other 0x7fc2637a6a90: {{0.0, 0.0}, {375.0, 20.0}}
这可能是我呈现的视图控制器,但我无法看到任何对象是由于它们都是由于#34;其他"
答案 0 :(得分:0)
尝试直接通过内容访问单元格。
XCUIApplication *app = [[XCUIApplication alloc] init];
[app.staticTexts[@"Cell One"] tap];
答案 1 :(得分:0)
容器视图中的元素通常无法访问。使PopOverViewController无法访问,单元格应该可用。
self.isAccessibilityElement = false
在视图控制器上执行此操作,然后照常查询单元格。
app.cells.elementBoundByIndex(0).tap()
答案 2 :(得分:0)
我设法通过删除故事板上启用的辅助功能标志来解决此问题。在此之后,细胞在元素检查器中变得可见。