I want to tap "Next" button in my view
lazy var Next = app.butons["Next"] Next.tap()
I am getting below error
Failed to get matching snapshot: Multiple matching elements found for <XCUIElementQuery: 0x280b0d4a0>.
I want to tap "Next" button in my view
lazy var Next = app.butons["Next"] Next.tap()
I am getting below error
Failed to get matching snapshot: Multiple matching elements found for <XCUIElementQuery: 0x280b0d4a0>.
Ignoring typos, what XCTest is telling you is that multiple things match what you're trying to identify. It would be helpful to know which one you're targeting specifically, but you could blindly try to tap the first:
app.buttons["Next"].firstMatch.tap()
If you need to get the 2nd you'll have to manipulate the array of matches and grab the element at index 1 (0 is the first, which is cheaper to get using the previous code):
app.buttons["Next"].element(boundBy: 1).tap()
I find getting the 2nd or last matches to be things I do often so I extend XCUIElementQuery
with computed properties var secondMatch
and var lastMatch
, where secondMatch
returns the above element and lastMatch
is the following:
extension XCUIElementQuery {
var lastMatch: XCUIElement {
return self.element(boundBy: self.count - 1)
}
}