insert button not hittable

I am attempting to write a UI test to verify an insert operation for a UITableView. I can access the button using the following code:


let insertButton = XCUIApplication().tables.containingType(.Cell, identifier: "MyCellType").buttons["Insert "]

insertButton.exists returns true

insertButton.hittable() return false

insertButton.tap() throws Assertion Failure: UI Testing Failure - Unable to find hit point for Button


If I set a break point at the insertButton.tap() statement, I can then tap the button in the simulator and it works. My test worked before upgrading to Xcode Version 7.1 (7B91b)


Any ideas why the standard insert button would not be hittable via code but is using the mouse on the simulator?

Replies

I have had to rewrite this section of the app for other reasons, but never figured out why this test broke. If anybody does hit this issue and finds a solution, I would still like to know it.

I had similar issue so this is what I did.

/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
func forceTapElement() { 
     if self.isHittable { 
          self.tap() 
     }
      else { 
          var coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0)) 
          coordinate.tap() 
     }
}

Now instead of calling tap(), I am calling forceTapElement(). This is more of workaround for bug with XCode 7.1, is it was working correctly before that.


More details at -

http://stackoverflow.com/questions/33422681/xcode-ui-test-ui-testing-failure-failed-to-scroll-to-visible-by-ax-action/33534187#33534187

Sandeep - how do you add this extension?


I'm still getting to grips with Swift.


I declare this extension outside my test class, builds ok, but when I run I get the error


caught "NSInvalidArgumentException", "-[XCUIElement forceTapElement]: unrecognized selector sent to instance 0x7fc8451fb140"

Thanks I was trying to hit the result cell from a UISearchController and this helped me to do it on xcode 7.3

I think the issue being the target element not visible in the screen. Scrolling the screen to the target element and then tapping on it worked for me.


while !button.hittable {
      XCUIApplication().scrollViews.elementBoundByIndex(0).swipeUp()
}