UI Automator 和 driver.swipe via appium 有什么区别

What is the different between UI Automator and driver.swipe via appium

我想知道 UI Automatordriver.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 是与 xy

不同之处在于实现和目的:

UIAutomator

  • 通过 UIAutomator 搜索元素允许实际滚动视图 up/down 到可搜索元素。首先,它是一个搜索动作,如果你有一个可滚动的视图并且知道其中的元素,你可以用它来滚动。所以需要:
  • 具有 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

操作 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 信息