I have a test that looks like the following:
func testNextButtonDisabled() {
let app = XCUIApplication()
XCTAssertFalse(app.buttons["Next"].enabled)
}
This test fails because, in addition to my own "Next" button that I've created, the keyboard return button is labeled 'Next'. This test fails with the error:
UI Testing Failure - Multiple matches found
How can I differentiate between my own 'Next' button and the keyboard 'Next' button?
The specific solution to this problem is to look for elements that are descendants of the main window.
func testNextButtonDisabled() {
let app = XCUIApplication()
XCTAssertFalse(app.childrenMatchingType(.Window).elementBoundByIndex(0).buttons["Next"].enabled)
}
For a general solution to solve problems like this: In Xcode run the "Record UI Test" again to see how Xcode thinks you should be referencing the element in which you're interested.
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