简体   繁体   English

Swift UITest在tableviewcell内找不到collectionview

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

I have a "collectionView" inside of a "tableViewCell" and at XCTest I can not access this "collectionview" or its "cells". 我在“ tableViewCell”中有一个“ collectionView”,在XCTest上,我无法访问此“ collectionview”或其“单元”。 here is my code to access this "collectionview". 这是我访问此“ collectionview”的代码。 Also I used accessibilityIdentifier but there is nothing change. 我也使用了accessibilityIdentifier,但是没有任何变化。 I can access "tableViewCell" but can not to "collectionView" 我可以访问“ tableViewCell”,但不能访问“ collectionView”

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

If I understand the question correctly, the reason you cannot get the collectionViewCell is because in the collectionViewCell, there are some gesture responders such as a button. 如果我正确理解了该问题,则无法获取collectionViewCell的原因是因为在collectionViewCell中,有一些手势响应程序,例如按钮。 If there is no such subView or some dumb one like a label, still you can get the collectionViewCells as the following: 如果没有这样的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 , 

etc .. 等..

However, if there is a button in any cell, you can not get the cell directly: 但是,如果任何单元格中都有一个按钮,则无法直接获取该单元格:

  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.

Hope this answers your question why not getting the collection cell. 希望这能回答您的问题,为什么不获得收集单元。 Actually, you can refer the cell first then try to refer the button later by two steps. 实际上,您可以先引用单元格,然后再通过两个步骤尝试引用按钮。

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

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