簡體   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