XCUIElementQuery cells

I'm testing how many cells exists in collection view. I have following steps:


1. Load collection view with 4 items and show them in small cell with "smallCell" reuse identifier

2. Reload collection view with 2 items and show them in big cell with "bigCell" reuse identifier.


After that XCUIApplication().collectionViews.count returns 6 elements (4 small cells and 2 big cells). Is this expected behavior? I would also like to know what elements are returned when calling XCUIElementQuery. Visible cells in collection view? I'm using Xcode 7 beta 5.

I was able to get specific cells by adding accessibility identifier and then filtering elements by identifier but I think this isn't the correct way.

collectionViews.count gives you the number of collection views, not the number of cells.

collectionViews.cells.count gives you the number of cells. All cells are returned, not just the visible ones.

Thanks, it should have read collectionView.cells.count.


All cells are returned, not just the visible ones.


If I have 100 items in collection view it seems to return only the visible ones. Also after reloading the collection with reloadData, it also returns previously visible cells like I said in OP. So is it a bug?

Hm... That's unexpected, at least to me. Please file a bug report (using the Report Bugs link at the bottom of this page).

ID: 22309497 related to the query after reloading the collection view

ID: 22309612 related to the wrong number of elements

Thanks!

Has this bug already been fixed?

I have a similar problem with this code:

XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElementQuery *allCells = app.collectionViews.cells


After reloading the UICollectionView, my variable allCells has two more elements than expected. I noticed that this issue only occurs when the collectionView has fewer elements than before.

Would be interesting to know, if this bug should've been fixed in Xcode 7.1.1.

Thanks in advance!


Best regards

Sven

In XCode 7.3, I am still seeing this as a problem. XCUIApplication().collectionViews.cells.count only returns the visible cell count. I also see a problem when in my app startup, I populate the collection view with cells, and it does see the correct number, although not all are visible. However, if I then add a new one via UI testing, it still reports the previous cell count.

In XCode 9.2, I am still seeing this as a problem. XCUIApplication().collectionViews.cells.count only returns the visible cell count.

Xcode 10.2.1, still only returns the visible cell count. 4 years with no update on this issue.


Opened dupe radar 50948199.

Xcode 12.4, still only returns the visible cell count.

I've run into the cell count issue today with Xcode 15 and iOS 17. application.otherElements["SomeVC"].collectionViews.cells.matching(identifier: "SomeCell").count only returns the number of visible matching elements, and ignores the ones offscreen. Is there a known workaround for this?

XCUIElementQuery cells
 
 
Q