麻烦从UIAutomation中的UIAElementArray按名称获取元素 [英] Trouble Getting Elements by Name from UIAElementArray in UIAutomation

查看:234
本文介绍了麻烦从UIAutomation中的UIAElementArray按名称获取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIAutomation脚本中按名称获取界面元素时遇到了问题。

I'm having trouble getting interface elements by name in a UIAutomation script.

我已经为文本控件设置了辅助功能面板:

I have set up the accessibility panel for a text control:

我知道我有正确的父视图,因为此代码可用于设置字段内容:

And I know that I have the right parent view, as this code will work to set the field contents:

var view = UIATarget.localTarget().frontMostApp().mainWindow();
var textfields = view.textFields();
textfields[0].setValue("testuser");

不幸的是,如果我尝试按名称访问该字段,因为文档似乎表明我应该是能够做到,我收到一个错误:

Unfortunately, if I try to access the field by name, as the docs seem to indicate I should be able to do, I get an error:

var view = UIATarget.localTarget().frontMostApp().mainWindow();
var textfields = view.textFields();
textfields['foo'].setValue("testuser");

无法对无效元素执行操作:来自target.frontMostApp()的UIAElementNil.mainWindow()。textFields( )[foo]

Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().mainWindow().textFields()["foo"]

有没有人知道为什么这个名字找功能似乎不适合我?

Does anybody have any idea why the find-by-name functionality doesn't seem to be working here for me?

感谢您的见解!

推荐答案

如果您正在使用辅助功能层,那么您必须在设备/模拟器中启用它:

If you are working with the accessibility Layer, you must to enable it in the Device/Simulator:


设置 - >常规 - >辅助功能 - >辅助功能检查器 - >开启

Settings-> General-> Accessibility-> Accessibility Inspector-> ON

这篇关于麻烦从UIAutomation中的UIAElementArray按名称获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆