We were using this code to simulate a tap on the first cell of a UICollectionView
on Xcode UI Testing:
XCUIElementQuery *query = [application descendantsMatchingType:XCUIElementTypeAny];
XCUIElement *collectionView = [query objectForKeyedSubscript:collectionViewAccessibilityIdentifier];
XCUIElement *targetCell = [lensesCollectionView.cells elementBoundByIndex:cellIndex];
if (targetCell.hittable) {
[targetCell tap];
}
this works fine on iOS 10, but stopped working on iOS 11. The targetCell
is never hittable
no matter what. Adding a sleep(10)
before XCUIElement *targetCell = [lensesCollectionView.cells elementBoundByIndex:lensIndex]
doesn't help.
I've seen hacky solutions mentioned elsewhere such as
func forceTapElement() {
if self.isHittable {
self.tap()
} else {
var coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
coordinate.tap()
}
}
but that doesn't look very clean. What's the cleanest way of achieving this?
Update: If I try to tap it without checking for hittable
I get this error:
error: Error -25204 performing AXAction 2003 on element pid: 43616, elementOrHash.elementID: 4882574576.240
It turns out that isAccessibilityElement
was NO
on our custom collection view cells on iOS 11 (strangely, it was YES
on iOS 10). Explicitly setting it to YES
fixed the issue.