我在“tableViewCell”中有一个“collectionView”,在 XCTest 中我无法访问这个“collectionview”或其“cells”。这是我访问此“collectionview”的代码。我也使用了 accessibilityIdentifier 但没有任何变化。我可以访问“tableViewCell”但不能访问“collectionView”
app.tables.cells.element(boundBy: 7).collectionViews.element(boundBy: 0).cells.element(boundBy: 0)
最佳答案
如果我没理解错的话,你无法获取collectionViewCell的原因是因为在collectionViewCell中,有一些手势响应器,比如一个按钮。如果没有这样的 subview 或一些像标签这样的愚蠢的 subview ,您仍然可以按如下方式获取 collectionViewCells:
let collectionViewsQuery = XCUIApplication().tables.children(matching: .cell).element(boundBy: 1).collectionViews // the second table cell
let element = collectionViewsQuery.children(matching: .cell).element(boundBy: 3).children(matching: .other).element // the fourth cell
let element2 = collectionViewsQuery.children(matching: .cell).element(boundBy: 4).children(matching: .other).element // the fifth cell ,
等..
但是,如果任何单元格中有一个按钮,则无法直接获取该单元格:
let tablesQuery = XCUIApplication().tables
let cell = tablesQuery.children(matching: .cell).element(boundBy: 1) // the second table cell
let button = cell.children(matching: .button).element(boundBy: 0) // the button which lies at any of collectionCell and not defined.
希望这能回答您为什么不获取收集单元的问题。实际上,您可以先引用单元格,然后再通过两个步骤尝试引用按钮。
关于ios - Swift UITest 在 tableviewcell 中找不到 collectionview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54129506/