问题
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