gpt4 book ai didi

ios - 在Xcode中的Instruments自动化模板中读取UILabel的值

转载 作者:行者123 更新时间:2023-12-01 16:03:08 24 4
gpt4 key购买 nike

我编写了以下脚本来点击UI上的按钮。每次按都会增加UILabel的整数值。我希望在我的脚本中读取UILabel的值。我该如何实现?我是Instruments中此自动化工具的新手。

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自动化模板中读取UILabel的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36549751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com