I'm using Appium 1.20. I'm trying to find a way to scroll to an element.

public static void scrollToElement(WebElement e) {
    JavascriptExecutor js = driver;
    HashMap scrollObject = new HashMap();
    scrollObject.put("direction", "down");
    scrollObject.put("name", e.getId()); // <-- there is no getId for WebElement.
    js.executeScript("mobile: scroll", scrollObject);

Unfortunately, there is no getId() for WebElement.

How do you scroll to an element in Appium 2?

  • May I know your targeted platform where you are unable to scroll? Nov 22, 2022 at 5:13

2 Answers 2


If it is android, you can use

driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"**/Put some text of scroll screen/**\").instance(0))")

You can use the following code to scroll to an element in Appium 2:

MobileElement element = (MobileElement) driver.findElementByXPath("//android.widget.TextView[@text='Element name']");

Point point = element.getLocation();
int startX = (int) (point.getX() * 0.5);
int endX = (int) (point.getX() * 0.5);
int startY = (int) (point.getY() * 0.5);
int endY = (int) (point.getY() * 0.8);

TouchAction touchAction = new TouchAction(driver);
touchAction.press(startX, startY).waitAction().moveTo(endX, endY).release().perform();

You can also use the scrollIntoView method as below:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);", element);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.