104

I'm trying to generate a UItest in Xcode. When I try to swipe UIview I get an error:

Timestamped Event Matching Error: Failed to find matching element

error window

enter image description here

This also happens if I try to tap UIView.

mfaani
  • 33,269
  • 19
  • 164
  • 293
shay
  • 1,211
  • 2
  • 8
  • 6
  • Can you explain a bit more? – Dieter Meemken Apr 14 '16 at 08:20
  • i try to swipe or tap on UIview that suppose to do something (has gesture reconizer) but when i do the gesture this error happens. the only way i mannged to make it work is with queries but its realy complicated and im sure that there is another way – shay Apr 14 '16 at 08:22

7 Answers7

49

You should verify that the 'Accessibility' option is enabled for the UIView object you are swiping from, for example:

enter image description here

AmitW
  • 798
  • 8
  • 11
20

Usually this issue is observed when the parent element of the element yo want to record is set to isAccessibilityElement = true. In general, you have to have the parent element set to false to access the child element.

For example: if you have a UILabel inside a view, the accessibility should be set to false for the view and set to true for the UILabel.

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
Souma Paul
  • 201
  • 2
  • 2
  • 1
    This was exactly reproducable. As you said it does not work of the parent element is set to isAccessibilityElement = true ! After I switched it back to false it worked again. – pommes Aug 02 '19 at 17:49
2

For recording a new test, I don't think there's a solution yet. But, if you use an extension forcing tap with a test that already exists, works.

Example of use:

extension XCUIElement {

    func forceTapElement() {
        if self.hittable {
            self.tap()
        }
        else {
            let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
            coordinate.tap()
        }  
    }
}

func testSomethingWithCells() {

   let app = XCUIApplication()
   let cells = app.tables.cells
   sleep(1)
   cells.elementBoundByIndex(0).forceTapElement()
}

You can check the original post here:

Xcode UI test - UI Testing Failure - Failed to scroll to visible (by AX action) when tap on Search field "Cancel' button

Community
  • 1
  • 1
Sophy Swicz
  • 1,307
  • 11
  • 21
2

I've been occasionally running into this problem. Delete the app's directory from DerivedData seems to help.

Dave L
  • 171
  • 10
2

In Xcode 9.3, where this is apparently still a problem, what I did was:

  • Quit Xcode
  • Reset the Simulator's settings (Hardware -> Erase all contents and settings)
  • Quit the Simulator
  • Delete the derived data for the current app
  • Restart Xcode
  • Try recording again - it worked this time for me.
commanda
  • 4,841
  • 1
  • 25
  • 34
  • I have provided the identifier as "skipButton" for a button and on identifying button , it always use to fails, I am identifying the button as app.buttons["skipButton'] , appreciate your help – Sujit Baranwal Jun 04 '18 at 05:57
  • These steps did not work for me. In fact, widgets that were not previously affected by the problem became affected. – Geoff S Jul 19 '18 at 05:36
  • why does this have no content? – dcrow Jun 20 '19 at 18:36
1

A solution that worked for myself was to identify the object differently.
In Xcode 8 I was able to use the following:

XCUIApplication().tables.cells["Camera Roll"].buttons["Camera Roll"].tap()

With Xcode 9 I got the error mentioned in this question. Ended up using the following, which worked (al beit more flakey than the original option)

XCUIApplication().cells.element(boundBy: 1).tap()
Charlie S
  • 4,366
  • 6
  • 59
  • 97
0

Even if you have Accessibility enabled for the element, you have to make sure that it has a unique accessibility identifier. In my case, I had copied & pasted a UISwitch and assigned a different outlet to it, but it kept the same accessibility ID as the original one.

NRitH
  • 13,441
  • 4
  • 41
  • 44