Timestamped Event Matching Error: Failed to find matching element
Asked Answered
S

7

103

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.

Systole answered 14/4, 2016 at 7:52 Comment(2)
Can you explain a bit more?Bulk
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 waySystole
S
49

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

enter image description here

Sherwood answered 24/8, 2016 at 10:52 Comment(5)
Turning Accessibility on for a WebView made my tests fail when resolving text in the WebView. Turning Accessibility OFF for the UIView hosting the WebView made the tests succeed. So beware.Transpose
As another point to make it work for me I had to give it a labelEmoryemote
I found this post helpful in for using fastlane to take screenshots of a tableView. https://mcmap.net/q/211981/-xcode-ui-test-accessibility-query-fail-on-uitableviewcellAlexia
Where is this? How do I set this?Goldarn
@CoryMcAboy you can set it from code for your custom view: isAccessibilityElement = trueAlbinaalbinism
I
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.

Ingather answered 2/4, 2019 at 9:40 Comment(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.Laclair
L
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

Lelahleland answered 31/5, 2016 at 9:12 Comment(1)
elementBoundByIndex' has been renamed to 'element(boundBy:)', Eg: cells.element(boundBy: 0).tap()Savonarola
H
2

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

Hoffer answered 24/8, 2017 at 18:42 Comment(0)
V
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.
Valine answered 24/4, 2018 at 16:4 Comment(3)
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 helpUnexceptional
These steps did not work for me. In fact, widgets that were not previously affected by the problem became affected.Buie
why does this have no content?Eschatology
F
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()
Fairing answered 21/9, 2017 at 11:15 Comment(1)
@Developer in your test functionTingey
E
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.

Examination answered 10/8, 2021 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.