当UIAutomation无法找到元素时,您应该使用它 . 它's quicker than XPath but is useful when UIAutomation doesn' t让你在一个元素(我认为 .actionSheets() 被打破 . 我在操作表启动时使用它,我需要 .click() 一个按钮)
UIAutomation
You should use Apple's UIAutomation, 2 framework as it is the quickest, native solution to iOS.
**Sample View Hierarchy**
<application>
<window>
<table name="Items">
<cell name="Foo, not in cart"></cell>
</table>
<table name="Cart">
<cell name="Bar. IM IN YOUR CART"></cell>
</table>
</window>
</application>
现在好了,找到数组中的那些单元格:
value = '.tableviews()["Cart"].cells()'
cells = driver.find_elements_by_ios_uiautomation(value)
1 回答
下面是我对Locators的细分以及我喜欢如何/为何使用iOS Automation . 所有这些都是基于我在Native iOS应用程序中的工作而体验的 .
Giant disclaimer: 我不是天生的 . 如果是这种情况,我建议坚持使用辅助功能ID和类名定位器策略 .
iOS自动化的定位器
CSS选择器
Appium中不存在CSS选择器 .
class 名称
你最接近CSS选择器的是类名选择器 . 我并没有真正使用它们,因为UIAutomation为我提供了我需要的东西,并允许我检查定位器策略中元素的名称/文本 .
XPath
你不想使用XPath,因为它在iOS上很慢而且很有趣 . (它有时会返回一个完全不正确的元素) . 它有时会导致仪器无故失败 . 强烈建议远离XPath .
辅助功能ID
当UIAutomation无法找到元素时,您应该使用它 . 它's quicker than XPath but is useful when UIAutomation doesn' t让你在一个元素(我认为
.actionSheets()
被打破 . 我在操作表启动时使用它,我需要.click()
一个按钮)UIAutomation
You should use Apple's UIAutomation, 2 framework as it is the quickest, native solution to iOS.
UIAutomation框架允许您使用类和层次结构来指定所需的元素 . 使用Appium时,请使用webdriver上的
find_elements_by_ios_uiautomation
功能 .Example Usage here
但是示例用法并没有告诉你UIAutomation真的有多强大 . 我遇到的一个常见问题是当屏幕上有多个tableview时,试图找到tableview的所有单元格 .
查找UIATableview“购物车”的所有UIACell
现在好了,找到数组中的那些单元格:
Extra Reading: Guide它超越了谓词以及为什么它们很棒
UIAutomation的限制
如果您的元素没有可见名称 . (开发人员喜欢在"Hint Overlays"之后放置隐形按钮等 . )
Suggested Solution: 添加辅助功能ID,使用辅助功能ID定位器 .
测试定位策略
Inspector中有一个不错的地方(在Appium.app GUI中提供),它可以让你尝试任何你想要的定位器策略和值 . 你应该使用它 . 它非常有帮助 .