如何在Xcode7中的UITests下找到带谓词的按钮?

Bar*_*zyk 5 swift ios9 xcode-ui-testing xcode7.1beta

我需要访问以下按钮:

在此输入图像描述

这条线很好用:

app.buttons["Reorder 1, $27 000, LondonStreet, ok, Pending"]
Run Code Online (Sandbox Code Playgroud)

但这不是:

app.buttons.elementMatchingPredicate(NSPredicate(format: "accessibilityTitle BEGINSWITH[cd] %@", "Reorder 1"))
Run Code Online (Sandbox Code Playgroud)

Joe*_*tti 12

通过谓词查找元素时,必须使用XCUIElementAttributes协议.对于这个例子,我认为title实际上不会起作用,但尝试使用label(应该映射到accessibilityLabel).

由于某种原因,%@格式选项似乎在Swift中不起作用.另请注意"重新订购1"周围的额外单引号.

let predicate = NSPredicate(format: "label BEGINSWITH[cd] 'Reorder 1'")
let button = app.buttons.elementMatchingPredicate(predicate)
Run Code Online (Sandbox Code Playgroud)