Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 498
Roman Zakharov Avatar asked Dec 24 '22 05:12

Roman Zakharov


1 Answers

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()
like image 75
Roman Zakharov Avatar answered Dec 29 '22 11:12

Roman Zakharov