Monday, 29 February 2016

How to do Vertical Scroll in Appium without scrollTo()?

Hi everyone today we will see how to use scroll action in Appium Test case.As we know in latest version of appium swipe() and scrollTo() methods are depricated lets see an alternative way to scroll through as List View.

Video Tutorial - 

App Under Test -
Check out the below screenshot of the app which has ListView containing 50 rows . Each row contains Text and Toggle Button. When you click on the row text at the top you can check which row was clicked.
Vertical Scroll Testing with Appium
Vertical Scroll

Test Scenario-
1. Launch Activity.
2. Scroll to List item:25.
3. Click on the row text.
4. Click on the toggle button.
scroll top to bottom in Appium
Vertical Scroll

Test Case -

package com.example.anuja.appiumapplication;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.remote.DesiredCapabilities;


import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;

import static junit.framework.Assert.assertNotNull;

 * Created by Anuja on 2/8/2017.

public class HorizontalTabScroll
    AppiumDriver driver;
    Dimension size;

    public void testCaseSetup()throws  Exception

        DesiredCapabilities cap=new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android device");
        cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "4000");
        cap.setCapability(MobileCapabilityType.APP, "c://apks//listviewsample.apk");
        cap.setCapability("noReset", true);
        driver = new AndroidDriver(new URL(""), cap);

    public void testScroll()throws Exception
        AndroidElement list = (AndroidElement) driver.findElement("android:id/mobile_list"));
        MobileElement listGroup = list
                        .AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                                + "new UiSelector().text(\" List item:25\"));"));

    public void testCaseTearDown()
with this post you can write test code for Vertical Scroll up to specified dimensions , Vertical Scroll till you find the element  and vertical scroll till the end.

I hope you find this tutorial useful. Do share your feedback and questions in comments section below.Please follow me on social media to get latest post updates.


  1. driver.scrollTo("List item:25") is undefined for type AndroidDriver. How do I fix it? Thank advance.

  2. Hi, check this out -

  3. hi, I am using this method, but eclipse is saying that this method is depreciated, is there any other method round?

  4. hi,i am unable to get these 2 import can u plz guide me how to get these
    i am useing latest javaclient jar 5.0

  5. Can i get an apk file , please?

  6. I have textview element (Not list view item) which is not visible . It is visible only when i swipe/scroll up. I am unable to click it as it is not visible. How can i scroll up and click on that item

  7. This comment has been removed by the author.

  8. Its really helpful post. Could you please advise- how to achieve this on iOS Native App?


  9. Hi,Can you pls provide an example to do horizontal Scroll in Appium as well without using swipe() and scrollTo()function.

  10. Hi,
    Using your code I am able to scroll to the text but unable to select the text in dropdown. No element found error is being thrown. Below is the code:
    AndroidElement list = (AndroidElement) driver.findElement(""));
    MobileElement listGroup = list.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("+ "new UiSelector().text(\"GROCERY\"));"));
    assertNotNull (listGroup.getLocation());;

    1. This comment has been removed by the author.

    2. Instead of replace listGroup with the element you want to located and perform the action

  11. How to swipe list view and recycle view item horizontally

  12. From appium version 1.6.0 and onwanrds 'scrollTo' method is depreciated by appium. You can perform scrollTo action operation using swipe method. You just need to run a 'for' loop number of times you want to scroll for the presence of Element. In each loop check the presence of Element by getting list of required element. If Element found break the loop and click.

  13. This works for scroll down. How would you do for scroll up to an element?

  14. Please do write comment in your code. It would be more usefull to undersatnd.

  15. Sanket Gajbhiv12 May 2018 at 03:33

    Thanks a lot. It works.
    I was facing issue from so many days, now its working perfectly.