UI testing - No matches found for Descendants matching type... recording generated code
Asked Answered
J

2

10

I am getting an error

No matches found for Find: Descendants matching type NavigationBar from input {( Application, 0x60400019b790, pid: 20515, label: '<appname>' )}

but the code was generated by the recording function of XCUITest so I don't understand why it can't find the navbar. I have added an accessibilityIdentifier that is a localized string called dashboardNavBar to try and use that to find it instead but I am having trouble querying it. The current code I am using is:

func testLoginLogout() {
    let app = XCUIApplication()
    //login credentials and other code that takes me to dashboard of app
    app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
    app.sheets["Do you want to Logout ?"].buttons["OK"].tap()
}

and the app.navigationBars... line is the line that throws the error above. I was hoping someone could tell me why it is unable to locate this navBar or whatever the problem is, and how I can fix it or work around it using the accessibilityIdentifier. Thanks.

Januarius answered 30/11, 2017 at 18:31 Comment(1)
The recorded code saying that the element you want to tap is a button. You can tap on that button directly like app.buttons["AccessibilityID"].tap(). Else you can find it by debugging mode and type po app.buttons.debugdescription | Then it will print all the buttons. Then you can also Access the element by app.buttons.element(boundBy : indexofSpecificelement).tap(). let me know your findings.Recess
S
2

I know that it's might be a workaround and not a real solution, but what I did when I encountered this problem is added a check if the element exist and trying to run the same action two times. When you make a segue after this action, the element should not exist, and the second attempt to invoke won't be executed. For instance:

    func testLoginLogout() {
            let app = XCUIApplication()
            if (app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).exists) {
                app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
            }
// and if you will call it again the element should not exists, otherwise it will be called again

            if (app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).exists) {
                app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
            }

            if (app.sheets["Do you want to Logout ?"].buttons["OK"].exists) {
                app.sheets["Do you want to Logout ?"].buttons["OK"].tap()
            }
        }
Sleepless answered 8/2, 2020 at 8:55 Comment(0)
K
1

I had similar issue on my end with error in logs "No matches found for Descendants matching type Button from input.."

Got it resolved by implementing isScreenLoaded() function with a timeout as per below sample:

func isLoaded() {
    XCTAssertEqual(app?.staticTexts["Some screen text goes here.."].waitForExistence(timeout: 5), true)
  }
  func testMyScreen() {
    app = ApplicationManager.shared.launchApplication(launchEnvironment: ["screenName": "myScreen"])
    isLoaded()
    if let keyboard = app?.keyboards.firstMatch {
      verifyScreen(without: keyboard, identifier: "MyScreen",
             perPixelTolerance: 0.05,
             overallTolerance: 0.002)
    }
  }
Kola answered 1/3, 2023 at 3:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.