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

标签 swift ios9 xcode-ui-testing xcode7.1beta

我需要访问以下按钮:

enter image description here

这条线工作正常:

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/

相关文章:

swift - Apple Watch 加速度计是否提供正确的数据?

swift - iOS 9 中的 requestLocation() 多次调用 didUpdateLocation 委托(delegate)

ios - 从上到下方向呈现 View Controller

ios - Xcode UI 测试 UIKeyInput typeText

ios - 如何让失败案例快速通过 Xcode UITests?

ios - 在车速表应用程序中保持最大速度

swift - 调整 MapKit 搜索结果

ios - 在 iOS 应用程序的 UI 测试中禁用等待空闲状态

iphone - UICollectionViewCell 中的 UIButton 的圆角半径不起作用

xcode - Xcode7 | Xcode UI测试|如何处理位置服务警报?