user4278002
user4278002

Reputation: 1

Issue with scroll down in android Appium WebDriver

How can I scroll down for the element appearance in Appium WebDriver? We are using an emulator for automation.

Any suggestions/help would be appreciated.

Upvotes: 0

Views: 10632

Answers (6)

The man
The man

Reputation: 137

This should work OK:

driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Put the text you want to scroll to here\"));");

If you want to click on the element after scrolling to it, add a click() method:

driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Put the text you want to scroll to here\"));").click();

Upvotes: -1

Sachin Lal
Sachin Lal

Reputation: 1

Try using the below code to scroll till bottom: -

    Dimension size= driver.manage().window().getSize();
    int starty=(int)(size.height*0.80);
    int endy=(int)(size.height*0.20);
    int startx=size.width/2;
    driver.swipe(startx, starty, startx, endy, 3000);

Upvotes: 0

Akhilesh Sinha
Akhilesh Sinha

Reputation: 881

Since scrollTo() and many more related methods are deprecated now with the latest version of appium(1.6.3). You can try the below line of code. It worked for me, hope it works for you as well......you can change the dimension as per your requirements.

    Dimension dimensions = driver.manage().window().getSize();
    //System.out.println("Dimension value = "+dimensions);


    Double screenHeightStart = dimensions.getHeight() * 0.5;
    //System.out.println("Screen Height start Value="+screenHeightStart);


    int scrollStart = screenHeightStart.intValue();
    //System.out.println("Scroll Start Value="+scrollStart);

    Double screenHeightEnd = dimensions.getHeight() * 0.2;
   // System.out.println("Screen Height start End="+screenHeightEnd);

    int scrollEnd = screenHeightEnd.intValue();
    //System.out.println("Scroll end Value="+scrollEnd);


    driver.swipe(0,scrollStart,0,scrollEnd,2000);
    sleep(3000);

Upvotes: 0

Manza
Manza

Reputation: 3527

This works

    TouchAction action = new TouchAction(androidDriver);
    action.press(0, 500)
            .waitAction(200)
            .moveTo(0, 200)
            .release()
            .perform();

Just play with the coordinates to get the desidered swiping.

Upvotes: 3

Priyanka
Priyanka

Reputation: 11

For that you can use scrollToExact() or scrollTo() functions of the AppiumDriver

AppiumDriver driver = new AppiumDriver();

to scroll when string contains "abc"

driver.scrollTo("abc");

or for exact string "abc" appear you can use

driver.scrollToExact("abc");

Upvotes: 1

JM.Pascal
JM.Pascal

Reputation: 281

You can use

driver.scrollTo(value);

or

driver.swipe(start.x, start.y, end.x, end.y, duration)

For reference : http://appium.io/slate/en/0.18.x/?ruby#automating-mobile-gestures

Upvotes: 0

Related Questions