# How to perform scroll/swipe top to bottom

**URL:** <https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908>\
**Category:** Tutorials/Documentation\
**Created:** [December 4, 2017, 11:11am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908 "2017-12-04T11:11:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gireesh05](https://discuss.appium.io/user_avatar/discuss.appium.io/gireesh05/32/6367_2.png) [@Gireesh05](https://discuss.appium.io/u/Gireesh05)\
**Post date:** [December 4, 2017, 11:11am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/1 "2017-12-04T11:11:41Z")

</div>

Hi,

I am working on mobile App testing. I need help from you guys.  
I want to know, how to scroll/swipe from too to bottom in Appium.  
Also need to know, how to scroll until particular element found?  
Please check the below details which i am using.

Appium version @1.7  
Android version @6.0.1  
Device: Real Device(Redmi)  
TestNG

---

<div class="post-metadata">

**Author:** ![Bilal\_Jarwan](https://discuss.appium.io/user_avatar/discuss.appium.io/bilal_jarwan/32/6182_2.png) [@Bilal\_Jarwan](https://discuss.appium.io/u/Bilal_Jarwan)\
**Post date:** [December 4, 2017, 7:19pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/2 "2017-12-04T19:19:35Z")

</div>

you can use while loop contains swipe function and set in your condition to check if element appear

Ex :

While (driver.findElements(By.id(“your\_id”)).size()==0){

size = driver.manage().window().getSize();  
int starty = (int) (size.height \* 0.80);  
int endy = (int) (size.height \* 0.20);  
int startx = size.width / 2;  
System.out.println("starty = " + starty + " ,endy = " + endy + " , startx = " + startx);

driver.swipe(startx, starty, startx, endy, 3000);  
Thread.sleep(2000);  
driver.swipe(startx, endy, startx, starty, 3000);  
Thread.sleep(2000);  
}

once your element appear while will be stop and you can execute your action on it 🙂

i hope this help you

---

<div class="post-metadata">

**Author:** ![suryakanta939](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@suryakanta939](https://discuss.appium.io/u/suryakanta939)\
**Post date:** [December 7, 2017, 7:39am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/3 "2017-12-07T07:39:47Z")

</div>

@Bilal_Jarwan swipe function already deprecated from the 1.6.5 version onwards.so this function is not going to work.For swiping you have to use the TouchAction class.

---

<div class="post-metadata">

**Author:** ![Bilal\_Jarwan](https://discuss.appium.io/user_avatar/discuss.appium.io/bilal_jarwan/32/6182_2.png) [@Bilal\_Jarwan](https://discuss.appium.io/u/Bilal_Jarwan)\
**Post date:** [December 7, 2017, 9:12am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/4 "2017-12-07T09:12:29Z")

</div>

@suryakanta939 its working for me, that’s why i suggest this solution

---

<div class="post-metadata">

**Author:** ![suryakanta939](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@suryakanta939](https://discuss.appium.io/u/suryakanta939)\
**Post date:** [December 7, 2017, 9:33am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/5 "2017-12-07T09:33:21Z")

</div>

@Bilal_Jarwan yes it will work but for the appium version bellow 1.6.5 .But question was for appium 1.7  
Thanks:slightly\_smiling\_face:

---

<div class="post-metadata">

**Author:** ![Bilal\_Jarwan](https://discuss.appium.io/user_avatar/discuss.appium.io/bilal_jarwan/32/6182_2.png) [@Bilal\_Jarwan](https://discuss.appium.io/u/Bilal_Jarwan)\
**Post date:** [December 7, 2017, 9:47am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/6 "2017-12-07T09:47:39Z")

</div>

@suryakanta939

yes, that’s right 🙂 thanks, also i have set the solution for the main issue 😉 how to swipe until you find you element.

---

<div class="post-metadata">

**Author:** ![Nemanja\_Maksic](https://discuss.appium.io/user_avatar/discuss.appium.io/nemanja_maksic/32/4115_2.png) [@Nemanja\_Maksic](https://discuss.appium.io/u/Nemanja_Maksic)\
**Post date:** [December 7, 2017, 10:28pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/7 "2017-12-07T22:28:29Z")

</div>

Heya, since I am struggling with the scrolling on Appium 1.7, can you please give me the example of the TouchAction class, or at least point me to the thread someone already explained?

---

<div class="post-metadata">

**Author:** ![VikramVI](https://discuss.appium.io/user_avatar/discuss.appium.io/vikramvi/32/116_2.png) [@VikramVI](https://discuss.appium.io/u/VikramVI)\
**Post date:** [December 13, 2017, 8:32pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/8 "2017-12-13T20:32:45Z")

</div>

Refer to [Swipe/Scroll best practice with Java-Client 5](https://discuss.appium.io/t/swipe-scroll-best-practice-with-java-client-5/18589/17) for consolidated answers

---

<div class="post-metadata">

**Author:** ![Nemanja\_Maksic](https://discuss.appium.io/user_avatar/discuss.appium.io/nemanja_maksic/32/4115_2.png) [@Nemanja\_Maksic](https://discuss.appium.io/u/Nemanja_Maksic)\
**Post date:** [December 14, 2017, 2:25pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/9 "2017-12-14T14:25:53Z")

</div>

> [@VikramVI](#):
>
> Refer to [Swipe/Scroll best practice with Java-Client 5 - #17 by VikramVI](https://discuss.appium.io/t/swipe-scroll-best-practice-with-java-client-5/18589/17) for consolidated answers

Not working for me, but I managed to make it work with TouchAction, see bellow.

```
TouchAction ta = new TouchAction(driver);
ta.press(Music).moveTo(GC).release().perform();

```

---

<div class="post-metadata">

**Author:** ![amodh](https://discuss.appium.io/user_avatar/discuss.appium.io/amodh/32/7083_2.png) [@amodh](https://discuss.appium.io/u/amodh)\
**Post date:** [December 18, 2017, 11:40am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/10 "2017-12-18T11:40:03Z")

</div>

Basically UiScrollable and UiSelector are the classes of android.  
You just need to enter element’s text to scroll up to that element.

driver.findElementByAndroidUIAutomator(“new UiScrollable(new UiSelector()).scrollIntoView(text(“Enter your element”))”);

---

<div class="post-metadata">

**Author:** ![Nemanja\_Maksic](https://discuss.appium.io/user_avatar/discuss.appium.io/nemanja_maksic/32/4115_2.png) [@Nemanja\_Maksic](https://discuss.appium.io/u/Nemanja_Maksic)\
**Post date:** [December 18, 2017, 12:20pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/11 "2017-12-18T12:20:43Z")

</div>

> [@amodh](#):
>
> Basically UiScrollable and UiSelector are the classes of android.  
> You just need to enter element’s text to scroll up to that element.
> 
> driver.findElementByAndroidUIAutomator(“new UiScrollable(new UiSelector()).scrollIntoView(text("Enter your element"))”);

How would you perform scroll if you have no other way to catch element than using webview?  
So you switchdriver webview and you want then to grab element and scroll, is it possible by UiAutomator?

---

<div class="post-metadata">

**Author:** ![JD](https://discuss.appium.io/user_avatar/discuss.appium.io/jd/32/1294_2.png) [@JD](https://discuss.appium.io/u/JD)\
**Post date:** [December 18, 2017, 5:09pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/12 "2017-12-18T17:09:09Z")

</div>

Here is an example using (x,y) coordinates

TouchAction ts = new TouchAction(driver);  
ts.press(207, 582).moveTo(8, -360).release().perform();

---

<div class="post-metadata">

**Author:** ![Nemanja\_Maksic](https://discuss.appium.io/user_avatar/discuss.appium.io/nemanja_maksic/32/4115_2.png) [@Nemanja\_Maksic](https://discuss.appium.io/u/Nemanja_Maksic)\
**Post date:** [December 19, 2017, 8:54am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/13 "2017-12-19T08:54:48Z")

</div>

Working, but how you come across those numbers(coordinates)?  
Is there any more sophisticated way of scrolling when dealing with webview?

---

<div class="post-metadata">

**Author:** ![Gireesh05](https://discuss.appium.io/user_avatar/discuss.appium.io/gireesh05/32/6367_2.png) [@Gireesh05](https://discuss.appium.io/u/Gireesh05)\
**Post date:** [December 19, 2017, 11:03am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/14 "2017-12-19T11:03:42Z")

</div>

@Bilal_Jarwan  
I tried to use the below code…  
Dimension size = driver.manage().window().getSize();  
int starty=(int)(size.height_0.5);  
int endy=(int)(size.height_0.2);  
int startx=size.width/2;  
driver.swipe(startx,endy,startx,starty,2000);

But getting an error message like: “The method swipe(int, int, int, int, int) is undefined for the type AndroidDriver”. Can you please let me know the resolution

---

<div class="post-metadata">

**Author:** ![Gireesh05](https://discuss.appium.io/user_avatar/discuss.appium.io/gireesh05/32/6367_2.png) [@Gireesh05](https://discuss.appium.io/u/Gireesh05)\
**Post date:** [December 19, 2017, 11:04am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/15 "2017-12-19T11:04:38Z")

</div>

@Bilal_Jarwan  
I tried to use the below code…  
Dimension size = driver.manage().window().getSize();  
int starty=(int)(size.height_0.5);  
int endy=(int)(size.height_0.2);  
int startx=size.width/2;  
driver.swipe(startx,endy,startx,starty,2000);

But getting an error message like: “The method swipe(int, int, int, int, int) is undefined for the type AndroidDriver”. Can you please let me know the resolution

---

<div class="post-metadata">

**Author:** ![JD](https://discuss.appium.io/user_avatar/discuss.appium.io/jd/32/1294_2.png) [@JD](https://discuss.appium.io/u/JD)\
**Post date:** [December 20, 2017, 5:31pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/16 "2017-12-20T17:31:43Z")

</div>

Can you use the inspector tool to get your x/y coordinates?

---

<div class="post-metadata">

**Author:** ![amodh](https://discuss.appium.io/user_avatar/discuss.appium.io/amodh/32/7083_2.png) [@amodh](https://discuss.appium.io/u/amodh)\
**Post date:** [December 22, 2017, 6:24am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/17 "2017-12-22T06:24:27Z")

</div>

Hey you can try this one ,works for me for an app devloped in react native.  
I hope the comments will help you .  
public void scrollUp() throws Exception {  
// Get the size of screen.  
Dimension size = driver.manage().window().getSize();  
// Find swipe start and end point from screen’s with and height.  
// Find start y point which is at bottom side of screen.  
int starty = (int) (size.height \* 0.80);  
// Find end y 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;

```
	// Swipe from Bottom to Top.
	driver.swipe(startx, starty, startx, endy, 3000);
	Thread.sleep(2000);
}
```

---

<div class="post-metadata">

**Author:** ![amodh](https://discuss.appium.io/user_avatar/discuss.appium.io/amodh/32/7083_2.png) [@amodh](https://discuss.appium.io/u/amodh)\
**Post date:** [December 22, 2017, 6:38am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/18 "2017-12-22T06:38:58Z")

</div>

Sorry, but i have not tried for web view but you can use this single line code instead of defining a function and using it .i think there wont be an element without a text defining it, for what that element is .

---

<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 17, 2018, 12:26pm UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/19 "2018-07-17T12:26:46Z")

</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;   
}

---

<div class="post-metadata">

**Author:** ![Dharmakrish](https://discuss.appium.io/user_avatar/discuss.appium.io/dharmakrish/32/4668_2.png) [@Dharmakrish](https://discuss.appium.io/u/Dharmakrish)\
**Post date:** [August 10, 2018, 3:57am UTC](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908/20 "2018-08-10T03:57:16Z")

</div>

```
public void swiptToBottom()
	{
		Dimension dim = driver.manage().window().getSize();
		int height = dim.getHeight();
		int width = dim.getWidth();
		int x = width/2;
		int top_y = (int)(height*0.80);
		int bottom_y = (int)(height*0.20);
		System.out.println("coordinates :" + x + " "+ top_y + " "+ bottom_y);
		TouchAction ts = new TouchAction(driver);
		ts.press(x, top_y).moveTo(x, bottom_y).release().perform();
	}

```

Call the above method to swipe to bottom

[Next page](https://discuss.appium.io/t/how-to-perform-scroll-swipe-top-to-bottom/19908.md?page=2)
