首页 > 解决方案 > 如何进行水平滑动直到在 webdriverio 中找到用于移动自动化的所需元素?

问题描述

我想做水平滑动有没有什么方法可以使用appium webdriverio为Android手机完成。

标签: androidappiumwebdriver-io

解决方案


您可以使用io.appium.java_client.TouchAction创建自定义滑动方法

public void horizontalSwipeByPercentage(double startPercentage, double endPercentage,
                  double anchorPercentage, AppiumDriver<MobileElement> driver) {
  Dimension size = driver.manage().window().getSize();
  int anchor = (int) (size.height * anchorPercentage);
  int startPoint = (int) (size.width * startPercentage);
  int endPoint = (int) (size.width * endPercentage);

  new TouchAction(driver)
        .press(PointOption.point(startPoint, anchor))
        .waitAction(WaitOptions.waitOptions(ofSeconds(1)))
        .moveTo(PointOption.point(endPoint, anchor))
        .release().perform();
}

对于水平滑动,anchor 是固定的 y 坐标位置


推荐阅读