ios - Swift UITest 在 tableviewcell 中找不到 collectionview

标签 ios swift xcode xctest uitest

我在“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/

相关文章:

ios - 无法在 Swift 1.2 的 UITableViewDelegate 方法中使用自定义 TableViewCell 类

xcode - 为应用程序加载器选择文件以将 iOS 应用程序上传到商店时选择哪个文件?

iphone - 我可以将参数传递给 clickedButtonAtIndex 这是 iphone 方法吗?

ios - onFocusChange 在 SwiftUI tvOS 中未触发

ios - UIImagePickerController 在 iOS10 上崩溃

ios - 函数不改变变量(Swift)

ios - 如何成功地将ImageMagick集成到iOS中?

ios - 不了解 NavigationController 和 UIViewControllers 在 iOS 中的工作方式

iphone - 切换到应用程序时 default.png 使用什么

ios - NSCache UIImage 数据从一个 ViewController 传递到另一个 ViewController