Reputation: 149
I am unable to scroll down to the bottom of any page in an Android app using Appium. Multiple approaches were attempted, including those found on Stack Overflow. (It seems this challenge is common.) However, all attempts failed.
Environment:
System.out.println(driver.getContext());
, the result is NATIVE_APP
Please share any alternatives or refinements that can solve this problem. Any helpful suggestions are greatly appreciated!
The following summarizes the various approaches that were attempted:
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId(\"send-to-email-app\"));").click();
try {
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Send\"))");
}catch(Exception e) {
System.out.println("We got an error scrolling!");
}
driver.swipe(0, Startpoint,0,scrollEnd,1000);
...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(10, 10).moveTo(x, y).release().perform();
...TouchAction touch = new TouchAction(driver);
touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();
TouchAction().press(el0).moveTo(el1).release();
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(x, y)).perform();
MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().text(\"Android scrollbar test\")).getChildByText("
+ "new UiSelector().className(\"android.widget.TextView\"), \"Doe\")"));
MobileElement sendEmailButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId(\"content\")).scrollIntoView("
+ "new UiSelector().resourceId(\"add-task-button\"))"));
sendEmailButton.click();
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap params = new HashMap();
params.put("direction", "up");
js.executeScript("mobile: swipe", params);
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
appCapabilities.setCapability("autoWebview", "true");
Upvotes: 5
Views: 9111
Reputation: 2372
(2024 update). Since touch actions are obsolete here is a new recommended way to do it.
var finger = new PointerInputDevice(PointerKind.Touch);
var dimensions = appiumDriver.Manage().Window.Size;
var locationX = (int)(dimensions.Width * 0.5);
var locationStartY = (int)(dimensions.Height * 0.9);
var locationEndY = (int)(dimensions.Height * 0.3);
var start = new Point(locationX, locationStartY);
var end = new Point(locationX, locationEndY);
var swipe = new ActionSequence(finger);
swipe.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, start.X, start.Y, TimeSpan.Zero));
swipe.AddAction(finger.CreatePointerDown(MouseButton.Left));
swipe.AddAction(finger.CreatePointerMove(CoordinateOrigin.Viewport, end.X, end.Y, TimeSpan.FromMilliseconds(500)));
swipe.AddAction(finger.CreatePointerUp(MouseButton.Left));
appiumDriver.PerformActions(new List<ActionSequence> { swipe });
Upvotes: 0
Reputation: 238
As a variation on the options proposed above, here is another way of implementing TouchAction
in combination with press
and moveTo
methods that worked for me. This results in a downward screen swipe. You might need to simply adjust the coordinates to whatever works best on your client:
new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();
For additional info, you might check out these references:
Upvotes: 8