如何解决UI Automator 和 driver.swipe 通过 appium 有什么不同
当我尝试使用滚动查找元素时,我想知道 UI Automator
和 driver.swipe
之间有什么不同。
使用 UI Automator
我可以使用 element\elements
滚动并找到 text\text contains\id\text starts with
:
new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("' + text + '").instance(0))')
和 driver.swipe
是 x
和 y
解决方法
不同之处在于实施和目的:
UIAutomator
- 通过 UIAutomator 搜索元素允许将视图向上/向下滚动到可搜索元素。首先,它是一个搜索操作,如果您有一个可滚动的视图并且知道其中的元素,则可以将其用于滚动。所以它需要:
- 使用
scrollable=true
属性查看 - 知道元素 id、文本等来定位它
- 不能使用坐标
- 如果未找到元素则失败
- 不精确,一找到元素就停止滚动
MobileElement firstClickableEl = driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().clickable(true)"))
MobileElement elementInView = driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("' + text + '").instance(0))')
"))
More 信息
操作 API
Actions API 用于不同的手势,如触摸、点按、拖放、swipe 等。
- 无需定位元素
- 可以同时使用坐标和元素
- 如果您传递正确的坐标,则更精确
TouchAction swipe = new TouchAction(driver)
.press(element(images.get(2),-10,center.y - location.y))
.waitAction(waitOptions(ofSeconds(2)))
.moveTo(element(gallery,10,center.y - location.y))
.release();
swipe.perform();
More 信息
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。