Timestamped Event Matching Error: Failed to find matching element

SwiftXcodeXcode Ui-Testing

Swift Problem Overview


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.

Swift Solutions


Solution 1 - Swift

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

enter image description here

Solution 2 - Swift

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.

Solution 3 - Swift

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.

Solution 4 - Swift

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:

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

Solution 5 - Swift

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

Solution 6 - Swift

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()

Solution 7 - Swift

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionshay View Question on Stackoverflow
Solution 1 - SwiftAmitWView Answer on Stackoverflow
Solution 2 - SwiftSouma PaulView Answer on Stackoverflow
Solution 3 - SwiftcommandaView Answer on Stackoverflow
Solution 4 - SwiftSophy SwiczView Answer on Stackoverflow
Solution 5 - SwiftDave LView Answer on Stackoverflow
Solution 6 - SwiftCharlie SeligmanView Answer on Stackoverflow
Solution 7 - SwiftNRitHView Answer on Stackoverflow