繁体   English   中英

Swift UITest在tableviewcell内找不到collectionview

[英]Swift UITest Can not find collectionview inside of tableviewcell

我在“ tableViewCell”中有一个“ collectionView”,在XCTest上,我无法访问此“ collectionview”或其“单元”。 这是我访问此“ collectionview”的代码。 我也使用了accessibilityIdentifier,但是没有任何变化。 我可以访问“ tableViewCell”,但不能访问“ collectionView”

app.tables.cells.element(boundBy: 7).collectionViews.element(boundBy: 0).cells.element(boundBy: 0)

如果我正确理解了该问题,则无法获取collectionViewCell的原因是因为在collectionViewCell中,有一些手势响应程序,例如按钮。 如果没有这样的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.

希望这能回答您的问题,为什么不获得收集单元。 实际上,您可以先引用单元格,然后再通过两个步骤尝试引用按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM