# How to do pull and refresh for android app?

**URL:** <https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507>\
**Category:** Support\
**Created:** [May 28, 2015, 6:51am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507 "2015-05-28T06:51:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Selvi\_Ranganathan](https://discuss.appium.io/user_avatar/discuss.appium.io/selvi_ranganathan/32/1675_2.png) [@Selvi\_Ranganathan](https://discuss.appium.io/u/Selvi_Ranganathan)\
**Post date:** [May 28, 2015, 6:51am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/1 "2015-05-28T06:51:14Z")

</div>

1. I need to automate the pull and refresh in android app. I am using java.
2. Is there any way to automate pull and refresh?

---

<div class="post-metadata">

**Author:** ![Mobile\_Test\_Test](https://discuss.appium.io/letter_avatar_proxy/v4/letter/m/a9a28c/32.png) [@Mobile\_Test\_Test](https://discuss.appium.io/u/Mobile_Test_Test)\
**Post date:** [May 28, 2015, 7:23am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/2 "2015-05-28T07:23:37Z")

</div>

u can use swipe functions

---

<div class="post-metadata">

**Author:** ![Selvi\_Ranganathan](https://discuss.appium.io/user_avatar/discuss.appium.io/selvi_ranganathan/32/1675_2.png) [@Selvi\_Ranganathan](https://discuss.appium.io/u/Selvi_Ranganathan)\
**Post date:** [May 28, 2015, 8:40am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/3 "2015-05-28T08:40:33Z")

</div>

k I will try the swipe method.

---

<div class="post-metadata">

**Author:** ![HelloAppium](https://discuss.appium.io/letter_avatar_proxy/v4/letter/h/87869e/32.png) [@HelloAppium](https://discuss.appium.io/u/HelloAppium)\
**Post date:** [July 14, 2015, 10:07am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/4 "2015-07-14T10:07:54Z")

</div>

Were you able to successfully do this? did you use the swipe method or something else?  
Thanks!!

---

<div class="post-metadata">

**Author:** ![Selvi\_Ranganathan](https://discuss.appium.io/user_avatar/discuss.appium.io/selvi_ranganathan/32/1675_2.png) [@Selvi\_Ranganathan](https://discuss.appium.io/u/Selvi_Ranganathan)\
**Post date:** [July 15, 2015, 11:02am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/5 "2015-07-15T11:02:40Z")

</div>

No, I have tried with swipe, it doesn’t work at all.

---

<div class="post-metadata">

**Author:** ![RajeshChidambaram](https://discuss.appium.io/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@RajeshChidambaram](https://discuss.appium.io/u/RajeshChidambaram)\
**Post date:** [August 19, 2015, 10:23am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/6 "2015-08-19T10:23:25Z")

</div>

Hi Guys

Even i searched a lot for pull down to refresh in android and IOS and found for scroll and used it to work it for pull to refresh. The following code works good for me for “Pull to Refresh” in a UIATable in IOS app.

import org.openqa.selenium.remote.RemoteWebElement;  
import java.util.HashMap;

WebElement element=driver.findElement(By.className(“UIATableCell”));   
JavascriptExecutor js = (JavascriptExecutor) driver;   
HashMap\<String, String\> scrollObject = new HashMap\<String, String\>();   
scrollObject.put(“direction”, “up”);   
scrollObject.put(“element”, ((RemoteWebElement) element).getId());   
js.executeScript(“mobile: scroll”, scrollObject);   
js.executeScript(“mobile: scroll”, scrollObject);

I have added the last line twice intentionally and so the code tries to scroll down twice and there you go it give a pull to bottom and my page got refresh with the refresh symbol on top, if this does not work, try scrolling to the top of the table before trying this code.

Note: In IOS there is no getId() but it does not pop up any issue for me.

---

<div class="post-metadata">

**Author:** ![Selvi\_Ranganathan](https://discuss.appium.io/user_avatar/discuss.appium.io/selvi_ranganathan/32/1675_2.png) [@Selvi\_Ranganathan](https://discuss.appium.io/u/Selvi_Ranganathan)\
**Post date:** [August 27, 2015, 12:16pm UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/7 "2015-08-27T12:16:32Z")

</div>

@RajeshChidambaram, Thanks your solution worked out well for pull and refresh.

1. I have tried with same code for scrolling to top to bottom of an page. Its scroll some 2 or 3 times. After that, it throws error as  
Error Message:-  
org.openqa.selenium.WebDriverException: An error occurred while executing user supplied JavaScript

2. It shows error in this line

js.executeScript(“mobile: scroll”, scrollObject);

// scroll down  
WebElement elements=driver.findElement(By.className(“UIACollectionCell”));  
for (int second = 0;; second++) {  
if(second \>=60){  
break;  
}  
JavascriptExecutor js = (JavascriptExecutor) driver;  
HashMap scrollObject = new HashMap();  
scrollObject.put(“direction”, “Down”);  
scrollObject.put(“elements”, ((RemoteWebElement) elements).getId());  
js.executeScript(“mobile: scroll”, scrollObject);  
sleep(5000);  
}

1. If you have any solution for scrolling from top to bottom of an page. Please provide a information.

---

<div class="post-metadata">

**Author:** ![sparda2](https://discuss.appium.io/letter_avatar_proxy/v4/letter/s/22d042/32.png) [@sparda2](https://discuss.appium.io/u/sparda2)\
**Post date:** [February 19, 2016, 1:53am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/8 "2016-02-19T01:53:46Z")

</div>

Hi all, in case you haven’t figured out like me one day ago, the solution is simple. Use the swipe method. Here is an example that worked for me in a nexus 5:

driver.swipe(411,290,411,900,2000);

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Jeevesh](https://discuss.appium.io/letter_avatar_proxy/v4/letter/j/54ee81/32.png) [@Jeevesh](https://discuss.appium.io/u/Jeevesh)\
**Post date:** [May 19, 2016, 2:19pm UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/9 "2016-05-19T14:19:28Z")

</div>

I tried this and it worked for me

//Get the size of screen.  
size = andoDriver.manage().window().getSize();  
//Find swipe start and end point from screen’s width and height.  
//Find starty point which is at bottom side of screen.  
int starty = (int) (size.height \* 0.90);  
//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);  
Thread.sleep(10000);  
//Swipe from Top to Bottom.  
andoDriver.swipe(startx, endy, startx, starty, 3000);

But now I am looking for how to verify if the loader was shown.

---

<div class="post-metadata">

**Author:** ![Rish\_Baranwal](https://discuss.appium.io/letter_avatar_proxy/v4/letter/r/a4c791/32.png) [@Rish\_Baranwal](https://discuss.appium.io/u/Rish_Baranwal)\
**Post date:** [July 26, 2018, 12:07pm UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/10 "2018-07-26T12:07:17Z")

</div>

It’s not working for me,I applied the above solution on Google Pixel, but it fails the problem I am facing is that when the android screen load completely after the service request complete we are not getting the element from the screen, for that reason we tried to refresh the screen, spent my complete day, but fails, pleas help.

---

<div class="post-metadata">

**Author:** ![loadingdude](https://discuss.appium.io/letter_avatar_proxy/v4/letter/l/ba8739/32.png) [@loadingdude](https://discuss.appium.io/u/loadingdude)\
**Post date:** [December 13, 2019, 9:56am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/11 "2019-12-13T09:56:38Z")

</div>

Hi …!  
Can u explain how it works ?

---

<div class="post-metadata">

**Author:** ![coolvasanth](https://discuss.appium.io/user_avatar/discuss.appium.io/coolvasanth/32/7085_2.png) [@coolvasanth](https://discuss.appium.io/u/coolvasanth)\
**Post date:** [April 17, 2020, 8:27am UTC](https://discuss.appium.io/t/how-to-do-pull-and-refresh-for-android-app/4507/12 "2020-04-17T08:27:10Z")

</div>

I tried with Swipe, no luck. Is there any alternative solution ? that is working ? if so, can someone add code snippet. I’m using c#, Even Java code is appreciated.
