How to scroll up/down in appium-android

你说的曾经没有我的故事 提交于 2019-12-08 11:35:04

问题


I have an app page where I need to scroll vertically to reach an element of the app.

I've googled and tried many solutions. Many commands are deprecated and don't support anymore in appium. Also, previous questions/answers in Stack didn't help me. I'm using appium v1.13.0 + Java (IntelliJ).

Sometimes I see this error:

java.lang.ClassCastException: io.appium.java_client.android.AndroidDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen

Anyway, my problem isn't just to solve the mentioned error. I'm looking for workable and correct commands to make a scroll action with appium. Please bring me the complete sample project cause I'm junior. Thanks


回答1:


Try this

String scrollViewContainer_finder = "new UiSelector().resourceIdMatches(\".*id/your_scroll_view_id\")";
String neededElement_finder = "new UiSelector().resourceIdMatches(\".*id/elemnt1\")";

WebElement abc = driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(" + scrollViewContainer_finder + ")" +
                ".scrollIntoView(" + neededElement_finder + ")"));



回答2:


My Swiping method:

public void swipe(int startX, int startY, int endX, int endY, int msDuration) {
    TouchAction touchAction = new TouchAction(mDriver);
    touchAction.press(PointOption.point(startX, startY))
            .waitAction(WaitOptions.waitOptions(Duration.ofMillis(msDuration)))
            .moveTo(PointOption.point(endX, endY))
            .release();

    touchAction.perform();
}



回答3:


For swiping vertically/horizontally I'm using TouchAction:

TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);
touchAction.press(startPoint)
           .waitAction(WaitOptions.waitOptions(Duration.ofMillis(waitBetweenSwipes)))
           .moveTo(endPoint)
           .release()
           .perform();


来源:https://stackoverflow.com/questions/57550682/how-to-scroll-up-down-in-appium-android

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