# Swipe from Right to Left

**URL:** <https://discuss.appium.io/t/swipe-from-right-to-left/10519>\
**Category:** Support\
**Created:** [June 3, 2016, 7:59am UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519 "2016-06-03T07:59:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lera\_Leschenko](https://discuss.appium.io/letter_avatar_proxy/v4/letter/l/f6c823/32.png) [@Lera\_Leschenko](https://discuss.appium.io/u/Lera_Leschenko)\
**Post date:** [June 3, 2016, 7:59am UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/1 "2016-06-03T07:59:22Z")

</div>

Hi!  
Please help , I’m new to testing.  
How to do swipe gestures in Android using Java?  
This code does not work

`` @Test public void testSlider(){ OpenMainMenu(); WebElement slider = driver.findElement(By.className("android.widget.ImageButton")); Point sliderLocation = getCenter(slider); driver.swipe(sliderLocation.getX(), sliderLocation.getY(), sliderLocation.getX()-100, sliderLocation.getY(), 3000); } private Point getCenter(WebElement element) { Point upperLeft = element.getLocation(); Dimension dimensions = element.getSize(); return new Point(upperLeft.getX() + dimensions.getWidth()/2, upperLeft.getY() + dimensions.getHeight()/2); } } ``

---

<div class="post-metadata">

**Author:** ![ravikr42](https://discuss.appium.io/user_avatar/discuss.appium.io/ravikr42/32/1493_2.png) [@ravikr42](https://discuss.appium.io/u/ravikr42)\
**Post date:** [June 3, 2016, 9:05am UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/2 "2016-06-03T09:05:10Z")

</div>

Hi @Lera_Leschenko

The code looks good, But I Guess there is some problem is getting the exact element locator , also do not manipulate MobileElement co-ordinate value.

In Android apps many elements can have same class name as “android.widget.ImageButton” and appium returns the MobileElement based on index basis, So probably you are not getting the exact MobileElement and hence swipe is not working properly.Try to narrow down your locator strategy so that you will get your desired MobileElement.

For swiping horizontally, capture the elements on both ends and user driver.swipe() method, and for vertical swipe capture top and bottom element and manipulate the co-ordinates in driver.swipe() method.

Let me know if this works for you.

Thanks  
Ravi Kumar

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [June 3, 2016, 9:59am UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/3 "2016-06-03T09:59:08Z")

</div>

1. log your actual numbers of start\_x, start\_y, end\_x and end\_y.
2. look at appium logs (start appium with debug key)
3. enable on phone in developer options Show touches + Show Show touch data. you will see where exactly swipe happens. try to do same manually (it could be problems when swipe actions starts/end on elements that consume touches e.g. button and swipe does not happen. in such case change swipe coordinates.)

you trying to swipe left?

---

<div class="post-metadata">

**Author:** ![pushpank](https://discuss.appium.io/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@pushpank](https://discuss.appium.io/u/pushpank)\
**Post date:** [June 3, 2016, 10:19am UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/4 "2016-06-03T10:19:02Z")

</div>

You can swipe with it .  
int Xfirst = findElementbyXpath("").getLocation().getX();  
int Xfirstr=Xfirst + Xfirst;  
int Yfirst= findElementbyXpath("").getLocation().getY();  
driver.swipe(Xfirst + 300,Yfirst, Xfirst,Yfirst,5000);

---

<div class="post-metadata">

**Author:** ![Lera\_Leschenko](https://discuss.appium.io/letter_avatar_proxy/v4/letter/l/f6c823/32.png) [@Lera\_Leschenko](https://discuss.appium.io/u/Lera_Leschenko)\
**Post date:** [June 3, 2016, 11:39am UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/5 "2016-06-03T11:39:08Z")

</div>

Hi @ravikr42

I have now turned this code , the action took place on Android, but the test failed.

`@Test public void SwipeLeftoRight() throws InterruptedException { OpenMainMenu(); size = driver.manage().window().getSize(); System.out.println(size); int star_x = (int) (size.width * 0.90); int end_x = (int) (size.width * 0.09); int star_y = size.height / 2; System.out.println("star_x = " + star_x + " ,end_x = " + end_x + " , star_y = " + star_y); //Right to left driver.swipe(star_x, star_y, end_x, star_y,500); }}`

That error  
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)

Test falls after the last line of code.

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [June 3, 2016, 1:38pm UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/6 "2016-06-03T13:38:25Z")

</div>

print little bit more log before and after

---

<div class="post-metadata">

**Author:** ![Anuja\_Bhatt](https://discuss.appium.io/user_avatar/discuss.appium.io/anuja_bhatt/32/2847_2.png) [@Anuja\_Bhatt](https://discuss.appium.io/u/Anuja_Bhatt)\
**Post date:** [October 10, 2017, 6:50pm UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/7 "2017-10-10T18:50:40Z")

</div>

Hi,

Here is detailed video on how you can swipe from left to right, right to left, from top to bottom and from bottom to top using Appium.

Thanks,  
Anuja

---

<div class="post-metadata">

**Author:** ![Rathan\_G](https://discuss.appium.io/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@Rathan\_G](https://discuss.appium.io/u/Rathan_G)\
**Post date:** [July 23, 2018, 7:54am UTC](https://discuss.appium.io/t/swipe-from-right-to-left/10519/8 "2018-07-23T07:54:34Z")

</div>

Hi anuja,

Your youtube videos are great and helpfull but im not able to find a solution to horizontal swipe in java client 5.0.4 using touch actions could u post a generic code its really urgent
