iOS - UI 自动化通过辅助功能标签获取文本字段?
因此,在我的 nib 文件中,我启用了辅助功能并将文本字段的辅助功能标签设置为“txt” 我正在尝试根据辅助功能名称找到此文本文件并更改其文本。
var target = UIATarget.localTarget();
var application = target.frontMostApp();
var mainWindow = application.mainWindow();
mainWindow.logElementTree();
// This works
var textField = mainWindow.textFields()[0];
//this doesn't work
var textField = mainWindow.textFields()["txt"];
textField.setValue("Hello");
我做错了什么吗?如何根据可访问性标签找到标签?
编辑:
我也对其他解决方案持开放态度,我试图避免基于索引获取文本字段
So in my nib file i enabled accessibility and set the accessibility label of a textfield to "txt"
I am trying to find this textfiled based on accessibility name and change its text.
var target = UIATarget.localTarget();
var application = target.frontMostApp();
var mainWindow = application.mainWindow();
mainWindow.logElementTree();
// This works
var textField = mainWindow.textFields()[0];
//this doesn't work
var textField = mainWindow.textFields()["txt"];
textField.setValue("Hello");
Am I doing anything wrong? How can I find a label based on accessibility label?
EDIT:
I am open to other solutions as well, I am trying to avoid getting the textfield based on the index
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的问题,在代码中而不是在 nib 文件中设置辅助功能标签值解决了我的问题。例如,我需要在 UIAutomation 脚本中访问一个 UITextField,我必须在 viewDidLoad 方法中设置辅助功能标签值,如下所示。
下面是我的 UIAutomation 脚本
I have a similar problem and setting the accessibility label value in the code instead in the nib file solve my problem. For example, I have a UITextField that I need to access in my UIAutomation script, I would have to set the accessibility label value in the viewDidLoad method as shown below.
and below is my UIAutomation Script