简体   繁体   English

如何在Appium-Android中向上/向下滚动

[英]How to scroll up/down in appium-android

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. 许多命令已弃用,appium中不再支持。 Also, previous questions/answers in Stack didn't help me. 此外,Stack中的先前问题/答案也无济于事。 I'm using appium v1.13.0 + Java (IntelliJ). 我正在使用appium v​​1.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. 我正在寻找可行且正确的命令来使appium进行滚动操作。 Please bring me the complete sample project cause I'm junior. 请带给我完整的示例项目,因为我是大三。 Thanks 谢谢

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

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 + ")"));

For swiping vertically/horizontally I'm using TouchAction: 对于垂直/水平滑动,我使用的是TouchAction:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过appium-android滑动图像并缩放 - Swipe images through appium-android and to zoom 无法在Android中使用Appium向下滚动 - Unable to scroll down in android with appium 如何使用appium和java向下滚动点击Android中的元素? - How to scroll down to click the element in Android using appium and java? 在 android Appium WebDriver 中向下滚动的问题 - Issue with scroll down in android Appium WebDriver Appium:如何使用Java在iOS应用中向下滚动下拉菜单 - Appium: How to scroll down drop down in an iOS app using Java Android / Java / Appium - 向下滑动(滚动)不起作用[移动应用] - Android / Java / Appium - Swipe (Scroll) Down does not work [Mobile App] 无法使用appium-android创建新会话,但是我给了正确的包名称 - Not able to create a new session using appium-android, however I am giving the right package name 如何使用 Appium 向下滚动以单击特定元素,因为 scrollTo 不起作用 - How to Scroll down to click a particular element using Appium as scrollTo is not working 如何使用 appium java 客户端 6.1.0 自动化 Android 手机底部的 Home、back、up、down、Menu 按钮? - How to automate Home,back,up,down,Menu button at bottom of Android phone using appium java client 6.1.0? 如何使用Java Appium Client在Android中滚动? - How to scroll in android using java appium client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM