我可以在界面生成器中设置辅助功能标识符吗? Xcode4.2
我只能在界面生成器中设置辅助功能标签,但在 UI 自动化中,我需要辅助功能标识符来获取 UI 元素。 有办法做到这一点吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我只能在界面生成器中设置辅助功能标签,但在 UI 自动化中,我需要辅助功能标识符来获取 UI 元素。 有办法做到这一点吗?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
可以使用身份检查器选项卡的“用户定义的运行时属性”在 IB 中设置accessibilityIdentifier:
键路径:accessibilityIdentifier
类型:字符串
值:选择的accessibilityIdentifier 文本
例如设置滚动视图以具有辅助功能 ID 'ScrollView':
注意:这只能用于具有accessibilityIdentifier 属性的项目,这意味着它们继承自UIView。另外,“关键路径”中的拼写错误可能会在加载项目时导致异常,我不相信会给出编译警告/错误。
The accessibilityIndentifier can be set in IB by using the Identity Inspector tab's 'User Defined Runtime Attributes':
Key Path: accessibilityIdentifier
Type: String
Value: Chosen accessibilityIdentifier text
E.g. setting a scroll view to have the accessibility ID 'ScrollView':
Note: This can only be used on items that have the accessibilityIdentifier property meaning they inherit from UIView. Also, typos in 'Key Path' will probably cause an exception when the item is loaded, I don't believe a compile warning/error would be given.
在 Xcode 7.1 (ios 9.0) 中你可以尽可能简单地做到这一点。请找到所附图片。
您可以简单地以 view.accessibilityIdentifier 的形式访问它
In Xcode 7.1 (ios 9.0) you could do it as simple as possible. Please find the image attached.
You could simply access it as view.accessibilityIdentifier
根据此页面
http://developer.apple.com/library/ios/#documentation/AnalysisTools/Conceptual/WhatsNewInstruments/NewFeatures42/NewFeatures42.html
如果未设置accessibilityIdentifier,UIAutomation将使用accessibilityLabel,所以你现在可以用它来代替。但这可能不是最佳实践,因为如果用户使用 VoiceOver,accessibilityLabel 对用户来说是可见的(或者更确切地说可听),但只要您为标签提供对人类有意义的名称就可以了。
希望Apple将来能够在IB中添加一种设置accessibilityIdentifier的方法,但现在您必须在代码中设置它,或者使用其他东西,例如视图标签来定位视图以实现自动化。
According to this page
http://developer.apple.com/library/ios/#documentation/AnalysisTools/Conceptual/WhatsNewInstruments/NewFeatures42/NewFeatures42.html
UIAutomation will use the accessibilityLabel if the accessibilityIdentifier is not set, so you can use that instead for now. This probably isn't best practice though because the accessibilityLabel is visible (or rather audible) to the user if they are using VoiceOver, but it's okay as long as you give the labels names that are meaningful to humans.
Hopefully Apple will add a way to set the accessibilityIdentifier in IB in future, but for now you'll have to set it in code, or use something else such as the view tag to target views for automation.
accessibilityIdentifier 仅适用于 IOS 5.0 或更高版本...请参考...
https://developer.apple.com/library/ios/documentation/uikit/reference/UIAccessibilityIdentification_Protocol/Introduction/Introduction.html
accessibilityIdentifier Only applicable for IOS 5.0 or Later....please Refer....
https://developer.apple.com/library/ios/documentation/uikit/reference/UIAccessibilityIdentification_Protocol/Introduction/Introduction.html
我想知道,你想测试 xib 中没有 IBOutlet 的东西吗?有更多经验的人可以分享他/她的想法吗?
这是我对这个问题的看法。
如果您不将 IBOutlet 分配给按钮/标签/texBox 或其他任何内容,这意味着您不会从代码中更改它。该控件将是静态的,您可以在界面生成器中看到它。
如果将 IBOutlet 添加到控件,则可以从代码中添加 accessIdentifier。
I was wondering, do you want to test things from xib that don't have IBOutlet? Can someone with more experience share his/hers thoughts?
Here is my view on the subject.
If you don't assign IBOutlet to a button/label/texBox or what ever this means you won't change it from the code. The control will be static and you can see it in Interface builder.
If you add an IBOutlet to a control then you can add acessibilityIdentifier from the code.