vinay sharma
vinay sharma

Reputation: 11

Right left swipe in appium

How to do Right and left in latest version of appium beacuse as we dont have swipe(driver.swipe) method in new appium version

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);
    }

Upvotes: 1

Views: 411

Answers (1)

Suban Dhyako
Suban Dhyako

Reputation: 2526

You can create a custom swipe method using 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();
}

Upvotes: 1

Related Questions