Left or Right swipe not working in appium for android app

Those coordinates depend on the size of your android. If you want to continue to use percentage you can use the following method:

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).moveTo(endPoint, anchor).release().perform();

    //In documentation they mention moveTo coordinates are relative to initial ones, but thats not happening. When it does we need to use the function below
    //new TouchAction(driver).press(startPoint, anchor).waitAction(duration).moveTo(endPoint-startPoint,0).release().perform();
}

And calling it with the value from your topic would be:

swipeHorizontal(driver,0.9,0.01,0.5,3000);

Notice the comments about absolute/relative values

3 Likes