ios - 使用 NSPredicate 选择任一输出

标签 ios swift ui-automation

当我在 XCode UI 测试中运行以下步骤时。我得到多个输出。

print(collectionViews.staticTexts.element(matching: NSPredicate(format: "(%@ IN identifiers), "price")).debugDescription)

输出:

Find: Elements matching predicate '"price" IN identifiers'
          Output: {
            StaticText 0x608000375f00: traits: 8589934656, {{24.0, 384.0}, {197.0, 27.5}}, identifier: 'price', label: '123'
            StaticText 0x6080003768c0: traits: 8589934656, {{24.0, 762.0}, {197.0, 27.5}}, identifier: 'price', label: '456'
          }

无论如何,我可以使用 swift.获得单个输出而不是多个输出吗?我正在尝试打印标签,即123

我正在寻找的输出:123

注意:标签值不断变化。

最佳答案

如果您在测试期间知道元素的索引,那么您可以根据索引路径定义accessibilityIdentifier,然后在 uiautomation 测试中使用它来获取元素。

例如:

// suppose label has traits of a button
label.accessibilityIdentifier = "<some constant>:\(indexPath.row)"

// test class
let label = table.buttons["<some constant>:\(<row index>)"] //this will give u only one element
label.tap()

关于ios - 使用 NSPredicate 选择任一输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39961667/

相关文章:

ios - 我如何使圆形 View 与桨碰撞

ui-automation - MS 团队 |无障碍洞察 |双显示器

c# - 模态窗口返回 null

ios - 对旧版本的iPhone禁用iPhone应用程序

ios - 获取所有包含 TextFields 的 TableView Cell 的数据(包括隐藏 View )

ios - CoreData 一次又一次地向数据库中添加数据

ios - Alamofire - 具有多个证书的 IOS SSL Pinning

python - 设置 PATH 后无法打开 uiautomatorviewer

ios - 如何判断我是否使用同一项来填充多个 UICollectionViewCell?

iphone - 在 NSLocalizedString() 中使用 "real"键是否安全?是否有保证的后备语言?