[英]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 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.
我正在寻找可行且正确的命令来使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.