ios - 读取 Xcode 中 Instruments 的 Automation 模板中 UILabel 的值

标签 ios xcode ios-ui-automation xcode-instruments

我编写了以下脚本来点击用户界面上的按钮。每次按下都会增加 UILabel 的整数值。我希望读取脚本中 UILabel 的值。我怎样才能实现这个目标?我是仪器中这个自动化工具的新手。

var target = UIATarget.localTarget();
var appName = target.frontMostApp().mainWindow().name;
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);
target.frontMostApp().mainWindow().buttons()["Increment"].tap();

最佳答案

首先确保您为该 UILabel 分配了辅助功能标识符。

您可以通过代码来做到这一点:

self.myLabel.accessibilityIdentifier = @"uniqueId";

或者通过 Storyboard:

enter image description here

要获取标签值,请在 UIAutomation 脚本中使用以下行:

target.frontMostApp().mainWindow().staticTexts()["uniqueId"].value();

关于ios - 读取 Xcode 中 Instruments 的 Automation 模板中 UILabel 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36549751/

相关文章:

ios - MKMapView 在 Tab-Bar 应用程序 (iOS) 中放大用户位置一次但不是第二次

ios - 在 Instruments 中录制 UI 交互时,我可以看到应用的脚本代码吗?

iphone - iOS 测试/规范 TDD/BDD 和集成与验收测试

ios - Cordova katzer 插件后台模式不适用于 iOS-9

ios - 使用静默 APNS 推送通知在没有用户通知的情况下发送 token ?

ios - 如果某些字符串为空,如何在 nsmutablearray 中添加字符串对象

c++ - 回车在 xcode 控制台 c++ 中不起作用

ios - iOS UI Automation 可以在没有真实设备或模拟器的情况下运行吗?

ios - 内存使用量增加

ios - 将 NSNumber 转换为 NSString 问题