XCTest UItesting:在表格单元格中找不到collectionView

有一个单元格包含一个集合视图。 我已经使用集合视图设置单元格

cell.accessibilityLabel = @"daren_shangjia_0001_add_new_photo_album"; 

然后在XCTest,我呢

 print(app.debugDescription); 

我没有看到我提供的accessibilityLabel。

 Element subtree: →Application 0x608000367200: {{0.0, 0.0}, {414.0, 736.0}}, label: '纳豆行' Window 0x608000365e80: Main Window, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000365880: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000365b80: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000365700: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000364d40: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000364680: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000364740: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000364800: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} NavigationBar 0x6080003648c0: traits: 35192962023424, {{0.0, 20.0}, {414.0, 44.0}}, identifier: '140' Button 0x608000364980: traits: 8589934593, {{20.0, 31.0}, {20.7, 20.5}}, label: 'da ren list backBtn' StaticText 0x608000365f40: traits: 8590000192, {{192.0, 28.0}, {30.0, 27.0}}, label: '140' Button 0x608000366000: traits: 8589934593, {{360.7, 25.0}, {33.3, 33.1}}, label: 'denglu 0010 you ke register' Other 0x608000366240: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x6000003660c0: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x600000365e80: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Table 0x600000365dc0: traits: 35192962023424, {{0.0, 0.0}, {414.0, 680.8}} Image 0x608000366a80: traits: 8589934596, {{0.0, 64.0}, {414.0, 219.6}} Image 0x608000366cc0: traits: 8589934596, {{168.4, 135.2}, {77.3, 77.3}} Button 0x608000367080: traits: 8589934593, {{151.8, 118.6}, {110.4, 110.4}} Image 0x6080003672c0: traits: 8589934596, {{245.2, 195.3}, {16.6, 16.6}}, identifier: 'da_ren_list_girl' 

要访问容器视图中的视图,您必须确保容器视图不可访问。 在你的情况下,我认为这是表格视图单元格。

 let cell = UITableViewCell! cell.isAccessibilityElement = false 

为了降低辅助function用户的复杂性,在屏幕的任何部分最多只能有一个可访问的视图。 一个单元格通常包含的信息可以概括为一个单一的实体,例如,表示一个项目,其中包括文本和图片可以select它。 由于您决定拥有相当复杂的单元格,因此您需要更改其默认行为,以便Accessibility用户更细粒度地访问单元格的内容。 它不能再在表格视图单元格级别进行总结。 因此,解释屏幕上的内容必须传递给视图层次结构中较低的元素。

要进一步了解这一概念,请尝试在启用VoiceOver的情况下使用您的应用程序,并使用三重三指轻按切换屏幕。

 Other 0x6080003642c0: traits: 8589934592, {{0.0, 283.6}, {414.0, 44.1}} StaticText 0x608000364380: traits: 8590000192, {{124.2, 283.6}, {165.6, 44.1}}, label: '0Samantha16|本科' Cell 0x608000364440: traits: 8589934592, {{0.0, 327.7}, {414.0, 185.4}} TextView 0x608000364500: traits: 140746078552064, {{11.0, 327.7}, {391.9, 185.4}}, value: 吴导是一位阳光帅小伙.在镇远从事导游... Other 0x6080003675c0: traits: 8589934592, {{0.0, 513.1}, {414.0, 0.1}} Other 0x608000367980: traits: 8589934592, {{0.0, 513.2}, {414.0, 44.1}} StaticText 0x608000367bc0: traits: 8590000192, {{124.2, 513.2}, {165.6, 44.1}}, label: '上传照片' Cell 0x608000363cc0: traits: 8589934592, {{0.0, 557.3}, {414.0, 185.4}}, label: 'DaRenDetailCell_1' StaticText 0x608000363e40: traits: 8589934656, {{35.5, 673.2}, {65.8, 27.6}}, label: '新build相册' StaticText 0x608000363d80: traits: 8589934656, {{106.9, 673.2}, {22.1, 27.6}}, label: '44' Other 0x608000363f00: traits: 8589934592, {{0.0, 560.8}, {414.0, 120.0}} Other 0x608000363fc0: traits: 8589934592, {{0.0, 560.8}, {414.0, 120.0}} Button 0x608000364080: traits: 8589934593, {{168.4, 649.9}, {77.3, 77.3}}, label: '订单' Other 0x608000364140: traits: 8589934592, {{0.0, 680.8}, {414.0, 55.2}} Image 0x608000364200: traits: 8589934596, {{0.0, 680.8}, {414.0, 55.2}}, identifier: 'WechatIMG9' Image 0x608000367500: traits: 8589934596, {{36.0, 686.3}, {22.1, 22.1}}, identifier: 'da_ren_ge_ren_zi_liao_0005_jian_jie' Image 0x608000369b40: traits: 8589934596, {{119.1, 686.3}, {22.1, 22.1}}, identifier: 'da_ren_ge_ren_zi_liao_0004_ren_gong_fu_wu' Image 0x608000369cc0: traits: 8589934596, {{272.8, 686.3}, {22.1, 22.1}}, identifier: 'da_ren_ge_ren_zi_liao_0003_na_dou_quan' Image 0x608000369c00: traits: 8589934596, {{355.9, 686.3}, {22.1, 22.1}}, identifier: 'da_ren_ge_ren_zi_liao_0002_gou_wu' Button 0x608000369a80: traits: 8589934593, {{5.5, 708.4}, {83.1, 22.1}}, label: '简介' Button 0x608000369f00: traits: 8589934593, {{88.6, 708.4}, {83.1, 22.1}}, label: '服务' Button 0x60800036a140: traits: 8589934593, {{242.3, 708.4}, {83.1, 22.1}}, label: '纳豆圈' Button 0x60800036a080: traits: 8589934593, {{325.4, 708.4}, {83.1, 22.1}}, label: '海淘' Window 0x60800036ad40: {{0.0, 0.0}, {414.0, 736.0}} Other 0x60800036ac80: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Window 0x60800036abc0: {{0.0, 0.0}, {414.0, 736.0}} StatusBar 0x60800036ab00: {{0.0, 0.0}, {414.0, 20.0}} Other 0x60800036aa40: {{0.0, 0.0}, {414.0, 20.0}} Other 0x60800036a980: {{0.0, 0.0}, {414.0, 20.0}} Other 0x60800036a8c0: traits: 8388608, {{6.0, 0.0}, {39.0, 20.0}} Other 0x60800036a800: traits: 8388608, {{50.0, 0.0}, {13.0, 20.0}}, label: '3 of 3 Wi-Fi bars', value: SSID Other 0x60800036a740: traits: 8389120, {{185.0, 0.0}, {48.0, 20.0}}, label: '7:27 PM' Other 0x60800036a680: traits: 8388608, {{384.0, 0.0}, {25.0, 20.0}}, label: '-100% battery power' 

我和你有同样的问题。 希望这段代码能帮助你。

 // Get the first Cell and don't forget to set id for your tableview let tableCellContainer = app.tables["HomeTableView"].cells.element(boundBy: 1) // Get collection cell which is has the text label inside is 'Brazil' let cell = tableCellContainer.staticTexts["Brazil"] cell.tap() XCTAssert(cell.exists)