6

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?

Senseful
  • 86,719
  • 67
  • 308
  • 465
kubi
  • 48,104
  • 19
  • 94
  • 118

1 Answers1

8

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.

ArielSD
  • 829
  • 10
  • 27
kubi
  • 48,104
  • 19
  • 94
  • 118