如何在 appium-android 中向上/向下滚动

我有一个应用程序页面,我需要在其中垂直滚动才能到达应用程序的元素。

我用谷歌搜索并尝试了很多解决方案。许多命令已被弃用,并且在 appium 中不再支持。此外,Stack 中以前的问题/答案对我没有帮助。我正在使用 appium v1.13.0 + Java (IntelliJ)。

有时我会看到这个错误:

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

无论如何,我的问题不仅仅是解决提到的错误。我正在寻找可行且正确的命令来使用 appium 进行滚动操作。请给我完整的示例项目,因为我是初中生。谢谢


不负相思意
浏览 174回答 3
3回答

12345678_0001

我的刷卡方法: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();}

慕森王

尝试这个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 + ")"));

慕勒3428872

对于垂直/水平滑动,我使用的是 TouchAction:TouchAction touchAction = new TouchAction((PerformsTouchActions) driver); touchAction.press(startPoint)            .waitAction(WaitOptions.waitOptions(Duration.ofMillis(waitBetweenSwipes)))            .moveTo(endPoint)            .release()            .perform();
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java