是否可以在XCTest中使用最后匹配的elemenst进行操作?

时间:2018-07-24 18:47:45

标签: ios swift xcode xctest xcode-ui-testing

我想点击应用中的最后 [播放]按钮,我正在寻找类似的东西

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

有什么办法吗?

1 个答案:

答案 0 :(得分:0)

我通过写一些扩展名

来解决了这个问题。
extension XCUIElementQuery {
    var lastMatch : XCUIElement {return self.element(boundBy: self.count - 1)}
}

之后,我可以像这样简单地编写代码

app.buttons.matching(identifier: "play").lastMatch.tap()