iOS自动化:如何点击没有id的按钮
我在 logElementTree
输出中有以下项目:
UIAButton: rect:{{20, 427}, {41, 41}}
UIAButton: rect:{{140, 427}, {41, 41}}
这些按钮没有标识符,没有名称,并且不在 XIB 中绘制。在我的自动化测试脚本中,我只使用索引(类似于 target.frontMostApp().mainWindow().buttons()[7].tap()
)
但是,这条线并不总是有效,因为指数正在变化。我只是想问一下,除了使用索引之外,还有其他方法可以点击这个按钮吗?请注意,该按钮没有名称,因此我无法使用 buttons()["name'"].tap()
I have the following items in logElementTree
output:
UIAButton: rect:{{20, 427}, {41, 41}}
UIAButton: rect:{{140, 427}, {41, 41}}
These buttons have no identifier, no name, and are not drawn in XIB. On my automation test script I only use index (something like target.frontMostApp().mainWindow().buttons()[7].tap()
)
But then, this line will not always work because index is changing. I just want to ask, if there's a way to tap this button other than using index? Please note that the button has no name, so I cannot use buttons()["name'"].tap()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从技术上讲,这将是完成您想做的事情的最佳方式,因此我将其留给看到此问题的其他开发人员。就您而言,由于您的技术经验有限,我建议您的开发人员为按钮分配 id 或名称。为按钮和其他 UI 元素提供良好的名称意味着视力受损的用户也可以访问您的应用程序,因为画外音会向他们读出您为按钮指定的名称。以下代码块将以编程方式为动态创建的符合
UIAccessibility
的对象分配标签和辅助功能提示。来自Apple的文档(在本例中,他们在视图上执行此操作,但您可以在按钮等任何对象上执行此操作):
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iPhoneAccessibility/Making_Application_Accessible/Making_Application_Accessible.html#//apple_ref/doc/uid/TP40008785-CH102-SW5
Javascript“hack”(不是很干净,但它有效......):
Technically this would be the best way to go about doing what you would like, so I'll leave it here for other developers who see this question. In your case since you have limited technical experience, I would recommend asking your developer to assign ids or names to buttons. Providing good names for buttons and other UI elements means that your app is also accessible for those users with impaired eyesight, since voiceover will read them the names you've given to your buttons. The following block of code will programmatically assign a label and a accessibility hint to a dynamically created object that conforms to
UIAccessibility
.From Apple's documentation (in this case they're doing it on a view, but you could do it on any object like a button):
http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iPhoneAccessibility/Making_Application_Accessible/Making_Application_Accessible.html#//apple_ref/doc/uid/TP40008785-CH102-SW5
Javascript "hack" (not very clean, but it works...):