Is it possible to operate with the last of matching elements in XCTest?
Asked Answered
I

1

8

I would like to tap the last [Play] button in my app, and I'm looking for something like

app.buttons["play"].lastMatch.tap()

Is there any way to do so?

Idona answered 24/7, 2018 at 18:47 Comment(0)
I
21

I managed this problem by writing a little extension

extension XCUIElementQuery {
    var lastMatch: XCUIElement { return self.element(boundBy: self.count - 1) }
}

after that, I can simply write code like this

app.buttons.matching(identifier: "play").lastMatch.tap()
Idona answered 25/7, 2018 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.