Search code examples
javaandroidappiumswipeappium-desktop

How to Swipe Horizontally using appium


# screen unable to swipe

I have 5 swipe screens and my code just stuck at 3rd screen i want to scroll Horizontally.


Solution

  • Use below method for swiping horizontally:

    public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
                Dimension size = driver.manage().window().getSize();
                int anchor = (int) (size.height * anchorPercentage);
                int startPoint = (int) (size.width * startPercentage);
                int endPoint = (int) (size.width * finalPercentage);
                new TouchAction(driver).press(startPoint, anchor).waitAction(Duration.ofMillis(duration)).moveTo(endPoint, anchor).release().perform();
            }
    

    Call the above method by:

    swipeHorizontal((AppiumDriver) driver,0.9,0.01,0.5,2000);