我需要访问以下按钮:
这条线工作正常:
app.buttons["Reorder 1, $27 000, LondonStreet, ok, Pending"]
但这不是:
app.buttons.elementMatchingPredicate(NSPredicate(format: "accessibilityTitle BEGINSWITH[cd] %@", "Reorder 1"))
最佳答案
通过谓词查找元素时,必须使用 XCUIElementAttributes
Protocol .对于这个例子,我不认为 title
会实际工作,但尝试使用 label
(应映射到 accessibilityLabel
)。
由于某些原因,%@
格式选项似乎在 Swift 中不起作用。另请注意“重新订购 1”周围的额外单引号。
let predicate = NSPredicate(format: "label BEGINSWITH[cd] 'Reorder 1'")
let button = app.buttons.elementMatchingPredicate(predicate)
关于swift - 如何在 Xcode7 的 UITests 下找到带谓词的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32520698/