Swift UITest 在 tableviewcell 中找不到 collectionview
Swift UITest Can not find collectionview inside of tableviewcell
我在 "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中,有一些手势响应,比如按钮。如果没有这样的子视图或一些像标签这样的愚蠢的子视图,你仍然可以得到如下的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.
希望这能回答您为什么不获取收集单元的问题。实际上,您可以先引用单元格,然后再通过两个步骤尝试引用按钮。
我在 "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中,有一些手势响应,比如按钮。如果没有这样的子视图或一些像标签这样的愚蠢的子视图,你仍然可以得到如下的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.
希望这能回答您为什么不获取收集单元的问题。实际上,您可以先引用单元格,然后再通过两个步骤尝试引用按钮。