Android - Appium Swipe down not working

不问归期 提交于 2019-11-29 08:07:50

Use below method for swiping down/up:

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

Call above method by:

For scroll up: swipeVertical((AppiumDriver)driver,0.9,0.1,0.5,3000);

For scroll down: swipeVertical((AppiumDriver)driver,0.1,0.9,0.5,3000);

Nauman Malik

Use this code to swipe up and down

TouchAction t=new TouchAction(driver);

//long press, for atleast 1 sec first and move the object

        WebElement First=driver.findElementByXPath("//*[@***First Element Path***]");

        WebElement second=driver.findElementByXPath("//*[@***Second Element Path***]");
t.longPress(longPressOptions().withElement(element(First)).withDuration(ofSeconds(3))).moveTo(element(second)).release().perform();

Hope this helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!