You can select the first cell in a collection view with:
let app = XCUIApplication()
app.launch()
let firstChild = app.collectionViews.childrenMatchingType(.Any).elementBoundByIndex(0)
if firstChild.exists {
firstChild.tap()
}
Swift 3
let firstChild = app.collectionViews.children(matching:.any).element(boundBy: 0)
if firstChild.exists {
firstChild.tap()
}
On a more theoretical note, your test suite should use deterministic data. You should always know exactly how many cells, and what they contain, will be returned from the service. You can accomplish this by using a seeded development server or mocking out network requests when running your test suite.