# Appium driver.swipe()

**URL:** <https://discuss.appium.io/t/appium-driver-swipe/19127>\
**Category:** Support\
**Created:** [October 11, 2017, 1:03pm UTC](https://discuss.appium.io/t/appium-driver-swipe/19127 "2017-10-11T13:03:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![shabareshh](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@shabareshh](https://discuss.appium.io/u/shabareshh)\
**Post date:** [October 11, 2017, 1:03pm UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/1 "2017-10-11T13:03:03Z")

</div>

package te;

import io.appium.java\_client.AppiumDriver;  
import io.appium.java\_client.android.AndroidDriver;

import java.net.MalformedURLException;  
import java.net.URL;  
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Dimension;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.remote.CapabilityType;  
import org.openqa.selenium.remote.DesiredCapabilities;  
import org.openqa.selenium.remote.RemoteWebDriver;

public class lanuch {

```
AppiumDriver d;

	 @SuppressWarnings("rawtypes")
	public void appLaunch() throws MalformedURLException {
	  DesiredCapabilities cap = new DesiredCapabilities();

	  
	  
	  cap.setCapability(CapabilityType.BROWSER_NAME, "");

	  cap.setCapability("deviceName", "T5511");

	  cap.setCapability("platformName", "Android");

	  cap.setCapability(CapabilityType.VERSION, "6.0.1");

	  cap.setCapability("platformVersion", "7.1.2");

	  cap.setCapability("appPackage", "com.smartron.tband");
	  cap.setCapability("appActivity", "com.smartron.sid.ui.setupflow.SetupFlowWelcomeScreen");

	  d = new AndroidDriver(new URL("http://127.0.0.1:4710/wd/hub"), cap);
	  System.out.println("connected");

	  d.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	  d.manage().window().getSize();
	  
	 }
	
	public void scroll() throws InterruptedException
	{
		Dimension dimensions = d.manage().window().getSize();
		
		for(int i=1; i>4; i++)
		{
			Double screenHeightStart = dimensions.getHeight() * 0.5;

			int scrollStart = screenHeightStart.intValue();

			Double screenHeightEnd = dimensions.getHeight() * 0.2;

			int scrollEnd = screenHeightEnd.intValue();

			d.swipe(0, scrollStart, 0, scrollEnd, 2000);

			
		}

```

}  
public static void main(String args[]) throws MalformedURLException{  
lanuch f=new lanuch();  
f.appLaunch();  
}

}

all code is correct d.swipe …unable to call the method

---

<div class="post-metadata">

**Author:** ![Jitu1888](https://discuss.appium.io/user_avatar/discuss.appium.io/jitu1888/32/7269_2.png) [@Jitu1888](https://discuss.appium.io/u/Jitu1888)\
**Post date:** [October 13, 2017, 3:16am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/2 "2017-10-13T03:16:09Z")

</div>

This method is deprecated from java client. You can use TouchAction class to swipe

---

<div class="post-metadata">

**Author:** ![Jitu1888](https://discuss.appium.io/user_avatar/discuss.appium.io/jitu1888/32/7269_2.png) [@Jitu1888](https://discuss.appium.io/u/Jitu1888)\
**Post date:** [October 13, 2017, 3:29am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/3 "2017-10-13T03:29:06Z")

</div>

new TouchAction(driver).press(startx, starty).waitAction(duration).moveTo(endx, endy).release().perform();

---

<div class="post-metadata">

**Author:** ![kunall17](https://discuss.appium.io/letter_avatar_proxy/v4/letter/k/c2a13f/32.png) [@kunall17](https://discuss.appium.io/u/kunall17)\
**Post date:** [February 26, 2018, 7:16am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/4 "2018-02-26T07:16:24Z")

</div>

Thank you so much for your reply

---

<div class="post-metadata">

**Author:** ![Jeeva](https://discuss.appium.io/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@Jeeva](https://discuss.appium.io/u/Jeeva)\
**Post date:** [February 26, 2018, 8:05am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/5 "2018-02-26T08:05:10Z")

</div>

I think the above swipe command is using absolute coordinates. Appium is now moved to the relative coordinate system.

you can use below code if needed,

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

---

<div class="post-metadata">

**Author:** ![Telmo\_Cardoso](https://discuss.appium.io/user_avatar/discuss.appium.io/telmo_cardoso/32/1435_2.png) [@Telmo\_Cardoso](https://discuss.appium.io/u/Telmo_Cardoso)\
**Post date:** [February 26, 2018, 1:21pm UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/6 "2018-02-26T13:21:49Z")

</div>

@Jeeva Why you say that?

What I can see if that it uses now only absolute values:

> <https://github.com/appium/appium-android-driver/pull/292>

---

<div class="post-metadata">

**Author:** ![Jeeva](https://discuss.appium.io/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@Jeeva](https://discuss.appium.io/u/Jeeva)\
**Post date:** [March 1, 2018, 7:15am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/7 "2018-03-01T07:15:32Z")

</div>

Sorry buddy … will update it. Thank you

---

<div class="post-metadata">

**Author:** ![mashkurm](https://discuss.appium.io/letter_avatar_proxy/v4/letter/m/97f17d/32.png) [@mashkurm](https://discuss.appium.io/u/mashkurm)\
**Post date:** [March 1, 2018, 12:28pm UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/8 "2018-03-01T12:28:05Z")

</div>

If someone doesn’t want to swipe through TouchAction then there is another method too. Find scrollable element thru AndroidUIAutomator and scroll till the text of the element.

---

<div class="post-metadata">

**Author:** ![NitinKumar](https://discuss.appium.io/user_avatar/discuss.appium.io/nitinkumar/32/4311_2.png) [@NitinKumar](https://discuss.appium.io/u/NitinKumar)\
**Post date:** [March 27, 2018, 12:18pm UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/9 "2018-03-27T12:18:33Z")

</div>

You can Try this and let me know if it’s help you

```
Dimension size=driver.manage().window().getSize();
	int width=(int)(size.width/2);
	int startPoint=(int)(size.getHeight() * 0.70);
	int endPoint=(int)(size.getHeight() * 0.20);
	int duration=2000;
	mobileDriver.swipe(width, startPoint, width, endPoint, duration);

```

Thank you.

---

<div class="post-metadata">

**Author:** ![urvashi\_jethva](https://discuss.appium.io/letter_avatar_proxy/v4/letter/u/74df32/32.png) [@urvashi\_jethva](https://discuss.appium.io/u/urvashi_jethva)\
**Post date:** [May 15, 2018, 9:04am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/10 "2018-05-15T09:04:27Z")

</div>

It is work with using PointerOption class.

TouchAction action = new TouchAction(d);  
PointOption p1= new PointOption();  
Dimension dimensions = d.manage().window().getSize();  
Double screenHeightStart = dimensions.getHeight() \* 0.5;  
int h1 = screenHeightStart.intValue();  
Double screenHeightEnd = dimensions.getHeight() \* 0.2;  
int h2 = screenHeightEnd.intValue();  
action.press(p1.point(0, h1)).moveTo(p1.point(0,-h2)).release().perform();

---

<div class="post-metadata">

**Author:** ![saurabh\_patel](https://discuss.appium.io/user_avatar/discuss.appium.io/saurabh_patel/32/5935_2.png) [@saurabh\_patel](https://discuss.appium.io/u/saurabh_patel)\
**Post date:** [July 5, 2018, 8:43am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/11 "2018-07-05T08:43:47Z")

</div>

Hi,

Is this for swiping from left to right on mobile screen?

Since I’m currently trying  
driver.swipe(780, 1400, -26, 1286, 682);

---

<div class="post-metadata">

**Author:** ![vinitaPatil](https://discuss.appium.io/letter_avatar_proxy/v4/letter/v/fbc32d/32.png) [@vinitaPatil](https://discuss.appium.io/u/vinitaPatil)\
**Post date:** [July 25, 2018, 9:27am UTC](https://discuss.appium.io/t/appium-driver-swipe/19127/12 "2018-07-25T09:27:16Z")

</div>

Hi, i have used the below code to Swipe / Scroll and it is working perfectly.  
Code to Swipe UP  
public boolean swipeFromUpToBottom()  
{  
try {  
JavascriptExecutor js = (JavascriptExecutor) driver;  
HashMap\<String, String\> scrollObject = new HashMap\<String, String\>();  
scrollObject.put(“direction”, “up”);  
js.executeScript(“mobile: scroll”, scrollObject);  
System.out.println(“Swipe up was Successfully done.”);  
}  
catch (Exception e)  
{  
System.out.println(“swipe up was not successfull”);  
}   
return false;   
}  
Code to Swipe DOWN  
public boolean swipeFromBottomToUp()  
{   
try {  
JavascriptExecutor js = (JavascriptExecutor) driver;  
HashMap\<String, String\> scrollObject = new HashMap\<String, String\>();  
scrollObject.put(“direction”, “down”);  
js.executeScript(“mobile: scroll”, scrollObject);  
System.out.println(“Swipe down was Successfully done”);  
}  
catch (Exception e)  
{  
System.out.println(“swipe down was not successfull”);  
}   
return false;   
}  
Code for carousel images swipe

public boolean swipeImages()  
{   
try {  
WebElement pageIndicator = driver.findElement(page\_indicator);  
String pageString= pageIndicator.getAttribute(“value”);  
int length = pageString.length();  
String count\_string= pageString.substring(length-2, length).trim();  
int count = Integer.parseInt(count\_string);  
System.out.println("Number of Image available to Swipe: "+count);  
for (int i=0; i\<=count; i++){   
JavascriptExecutor js = (JavascriptExecutor) driver;  
HashMap\<String, String\> scrollObject = new HashMap\<String, String\>();  
scrollObject.put(“direction”, “right”);  
js.executeScript(“mobile: scroll”, scrollObject);   
}  
System.out.println(“Swipe Successfully”);  
}  
catch (Exception e)  
{  
System.out.println(“Image swipe was not successfull”);  
}   
return false;   
}
