Pramod
Pramod

Reputation: 3767

How to scroll down a page

I want to scroll down to the bottom of the page, and perform an action. Using uiautomator, I have obtained the following:

index=2,
resource-id=com.manoramaonline.arogyam:id/pager,class=android.support.v4.view.ViewPager,
scrollable=true.

I have attempted to do this with the code below:

JavascriptExecutor js = (JavascriptExecutor) driver;
RemoteWebElement element =(RemoteWebElement)driver.findElement(By.xpath("//android.support.v4.view.ViewPager[@resource-id='com.manoramaonline.arogyam:id/pager']"));     
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");

// This is where the error is
scrollObject.put("element", element.getId());
js.executeScript("mobile: scroll", scrollObject);

Upvotes: 3

Views: 16982

Answers (4)

Alexandr Shchepkin
Alexandr Shchepkin

Reputation: 1

MobileElement radioGroup = (MobileElement) wd.findElementByAndroidUIAutomator("
    new UiScrollable(new UiSelector().resourceId(\"+<listview_id>+\"))
        .scrollIntoView(new UiSelector().text(\"+<your_text>+\"));
");
radioGroup.click();

method from Manidroid works for me perfectly

Upvotes: -1

Mani
Mani

Reputation: 1186

In recent update appium "mobile : scroll" deprecated, following code will work and video will help you to implement.

Scroll to text :

MobileElement radioGroup = (MobileElement) wd

.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"

".resourceId(\"+<listview_id>+\")).scrollIntoView("

"new UiSelector().text(\"+<your_text>+\"));");

radioGroup.click();

This link will help you : https://www.youtube.com/watch?v=bT3tqaLNn-Y

Upvotes: 0

SomeStudent
SomeStudent

Reputation: 3048

   JavascriptExecutor js = (JavascriptExecutor) driver;
            HashMap<String, String> scrollObject = new HashMap<String, String>();
            scrollObject.put("direction", "down");
            js.executeScript("mobile: scroll", scrollObject);

This code will scroll downwards, you can specify how many times you wish for it to scroll by placing it into a for loop. Only downside is that it is a nonspecific code. Again, this code is from one of their github answers, and as I mentioned, Appium is incapable of doing any proper scrolls for iOS. At least, I haven't located anything.

Upvotes: 0

Pramod
Pramod

Reputation: 3767

I got it working by following code.

    WebElement element = driver.findElement(By.className("android.widget.ScrollView"));
    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    // actions.click();
    actions.perform();

Upvotes: 0

Related Questions