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.
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()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With