右向左在鸦片上滑动

时间:2019-05-29 07:17:53

标签: selenium-webdriver appium ui-automation

如何在最新版本的appium中向右和向左移动,因为我们在新的appium版本中没有使用swipe(driver.swipe)方法

public DailyPicksPage swipeDailyPicksCard() throws Exception {
        Dimension size = agent.getMobileDriver().manage().window().getSize();
        System.out.println("Dimensions of the screen" + size);
        int startX = (int) (size.width * 0.80);
        int endX = (int) (size.width * 0.20);
        int width = size.width;
        int duration = 2000;
        int height = size.height;
        int pressHeight = (int) (height * 0.80);
        new TouchAction(agent.getMobileDriver()).press(PointOption.point(startX, pressHeight)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration))).moveTo(PointOption.point(endX, pressHeight)).release().perform();
        return new DailyPicksPage(params, agent);
    }

1 个答案:

答案 0 :(得分:1)

您可以使用 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();
}