How to do pull and refresh for android app?

  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?

u can use swipe functions

k I will try the swipe method.

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

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

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.

1 Like

@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){
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put(“direction”, “Down”);
scrollObject.put(“elements”, ((RemoteWebElement) elements).getId());
js.executeScript(“mobile: scroll”, scrollObject);

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

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:


Thanks :slightly_smiling:


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);
//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.

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.

Hi …!
Can u explain how it works ?

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.