I am trying to dismiss the search field by tapping \'Cancel\' button in search bar.
The test case is failing to find the cancel button. It was working fine in Xcode
I guess here "Cancel" button returns false for hittable property, that is preventing it from tapping.
If you see tap() in documentation it says
/*!
* Sends a tap event to a hittable point computed for the element.
*/
- (void)tap;
It seems things are broken with XCode 7.1.To keep myself (and u too ;)) unblocked from these issues I wrote a extension on XCUIElement that allows tap on element even if it is not hittable. Following can help you.
/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
func forceTapElement() {
if self.hittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
coordinate.tap()
}
}
}
Now you can call as
button.forceTapElement()
Update - For swift 3 use following:
extension XCUIElement {
func forceTapElement() {
if self.isHittable {
self.tap()
}
else {
let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx:0.0, dy:0.0))
coordinate.tap()
}
}
}