Delivered by FeedBurner

Appium - How To Swipe Vertical And Horizontal In Android Automation

Earlier In previous post, we learnt how to interact with android mobile gesture to perform drag and drop by generating action chain using TouchAction class of Webdriver 3. Swiping is another common action for any android mobile app. As you know, We can swipe horizontally(left to right or right to left) and swipe vertically(bottom to top and top to bottom) In android mobile app. Here I have described how to swipe horizontally and vertically In android mobile app using driver.swipe() when running appium automation test. Follow me throughout this article to learn how to swipe in android app using appium.

PREREQUISITES : Previous 19 steps(PART 1 and PART 2) of appium tutorials should be completed.

Download And Install SwipeListView Demo App
We will use SwipeListView Demo App for android swipe test using appium. You need to download and install SwipeListView Demo App in your android mobile device.
  • You can Download it from Google Play Store or THIS PAGE.
  • Install it in your android mobile device.
  • Open SwipeListView Demo App In your mobile device. It will show you alert message on screen.
  • Select "Don't show this message again" check box and click on OK button as shown in bellow image. Now this message will not display again when we run our test through appium.

  • It will show you list of apps in your android device. Using this app, You can swipe horizontal and vertical.
Aim To Achieve In This Appium Test
I have a 2 goals to achieve from this post in appium. 1. Horizontal swiping and 2. Vertical swiping in android app.

1. Horizontal Swiping In Android App
Using appium, We wants to swipe right to left and left to right horizontally as shown in bellow Image.

2. Vertical Swiping In Android App
Also we wants to swipe bottom to top and top to bottom vertically as shown in bellow Image.

This is our goal to achieve from this post.

Create And Run Appium Android Test Script To Swipe
I have prepared simple test to perform swipe on SwipeListView Demo android app as shown bellow. Create new class file and paste bellow given test script code in it.
package Android;


import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class driverSwipe {
 AndroidDriver driver;
 Dimension size;
 public void setUp() throws Exception {
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setCapability("deviceName", "ZX1B32FFXF");
  capabilities.setCapability("browserName", "Android");
  capabilities.setCapability("platformVersion", "4.4.2");
  capabilities.setCapability("platformName", "Android");
  capabilities.setCapability("appPackage", "");
  driver = new AndroidDriver(new URL(""),capabilities);
  driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
  WebDriverWait wait = new WebDriverWait(driver, 300);

 public void swipingHorizontal() throws InterruptedException {
  //Get the size of screen.
  size = driver.manage().window().getSize();
  //Find swipe start and end point from screen's with and height.
  //Find startx point which is at right side of screen.
  int startx = (int) (size.width * 0.70);
  //Find endx point which is at left side of screen.
  int endx = (int) (size.width * 0.30);
  //Find vertical point where you wants to swipe. It is in middle of screen height.
  int starty = size.height / 2;
  System.out.println("startx = " + startx + " ,endx = " + endx + " , starty = " + starty);

  //Swipe from Right to Left.
  driver.swipe(startx, starty, endx, starty, 3000);

  //Swipe from Left to Right.
  driver.swipe(endx, starty, startx, starty, 3000);

 public void swipingVertical() throws InterruptedException {
  //Get the size of screen.
  size = driver.manage().window().getSize();
  //Find swipe start and end point from screen's with and height.
  //Find starty point which is at bottom side of screen.
  int starty = (int) (size.height * 0.80);
  //Find endy point which is at top side of screen.
  int endy = (int) (size.height * 0.20);
  //Find horizontal point where you wants to swipe. It is in middle of screen width.
  int startx = size.width / 2;
  System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);

  //Swipe from Bottom to Top.
  driver.swipe(startx, starty, startx, endy, 3000);
  //Swipe from Top to Bottom.
  driver.swipe(startx, endy, startx, starty, 3000);

 public void End() {


swipingHorizontal() Method Description
In above test script, swipingHorizontal() method is responsible for horizontal swipe. Here,
  • driver.manage().window().getSize(); will find your device's screen size(Width X Height).
  • startx Is located at 70% (From left) of your device's screen width.
  • endx Is located at 30%  (From left) of your device's screen width.
  • starty Is located at the vertical middle of the screen.
  • First driver.swipe method will swipe from right side to left side as swipe start point(startx) is located at right side of the screen and end point(endx) is locate at left side of the screen. Here 3000 Is time in milliseconds to perform swipe operation. 
  • Second driver.swipe method will swipe from left side to right side as swipe start point(endx) is located at left side of the screen and end point(startx) is locate at right side of the screen.
  • Vertical point starty will remain steady as we are performing horizontal swipe.
swipingVertical() Method Description
swipingHorizontal() method is responsible for vertical swipe In above android automation script . Here,
  • starty Is located at 80% (From top) of your device's screen height.
  • endy Is located at 20%  (From top) of your device's screen height.
  • startx Is located at the horizontal middle of the screen.
  • First driver.swipe method will swipe from bottom to top as swipe start point(starty) is located at bottom side of the screen and end point(endy) is locate at top side of the screen. Here 3000 Is time in milliseconds to perform swipe operation. 
  • Second driver.swipe method will swipe from top side to bottom as swipe start point(endy) is located at top side of the screen and end point(starty) is locate at bottom side of the screen.
  • Horizontal point startx will remain steady as we are performing horizontal swipe.
I hope, Now you aware about how to run appium test script In android mobile device. Start appium server and run test script in eclipse and observe swipe operation in your android mobile screen.

This way you can swipe horizontal or vertical in any android application.


  1. I have to relocate the webelement from bottom to top, but above method is not working

  2. driver.swipe() is showing below error

    The method swipe(int, int, int, int, int) is undefined for the type WebDriver

  3. use AppiumDriver instead . goodLuck

  4. Use AppiumDriver instead of Webdriver

  5. Hay, this document help me Ton... but
    //Swipe from Bottom to Top. and //Swipe from Top to Bottom. is not working for me.
    AM using android WEBVIEW, am changing the context to NATIVE_APP to do swipe then also am not getting for TOP to BTTOM and BOTTOM to TOP.
    can you help me here....

  6. Geeting this error .Exception in thread "main" java.lang.NullPointerException
    at aptest.aptest.swipingHorizontal(
    at aptest.aptest.main(

  7. Hi. Is there any alternative method available which can do Swipe independent of the duration ?

  8. HI, Aravind
    I have learned lot from your tutorials. Thank very much.

    Hi, every body here
    If you can not run the script above, you should compare it with that in previous. you have to add the miss parts in it, then it works.


  9. This is Out Dated Code Please provide new once......

  10. hello @Aravind if you could provide the updated code for swipe both fro the horizontal and vertical by using appium 1.6.5 ,then it will be great