4

I am working with selenium 2.53 , Java 1.8 , Appium 1.5.3 for automation of Native mobile applications. Now i have a condition where length of page is too large and i have to click at the bottom of the page. If i do scroll page down manually while tests are running before clicking through automation- Click works fine. But i am unable to scroll down the page using code. I have tried many different code sets. right now i am trying the below code. But this as well is not working.

Now the question is: How can we scroll the page of native application to a specific element and click on that element?

JavascriptExecutor js = driver;
element = driver.findElement(getMethodToCall(object, byCall));
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
scrollObject.put("element", ((RemoteWebElement) element).getId());
js.executeScript("mobile: scroll", scrollObject);
1

In any of mobile testing services, handling of scroll can be done with the help of swipe method on Touch screen as mentioned below:

TouchAction touchAction = new TouchAction(driver); touchAction.press(x1,y1).moveTo(x2,y2).release(); driver.performTouchAction(touchAction4);

In this case, x1 and y1 refer to current coordinates. x2 and y2 refer to the new coordinate where the application should be scrolled to. Further, locator of elements can also be passed instead of its coordinates.

You can refer to below link for further reference on this: https://community.perfectomobile.com/posts/1087898-scrolling-in-appium

0

I don't think it is possible to scroll in native iOS or Android Apps via Javascript.

In Android it is possible to scroll using UIAutomator: https://developer.android.com/topic/libraries/testing-support-library/index.html#UIAutomator

Example usage:

protected MobileElement scrollToElementByTextContains(String text) {
    driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0))" +
            ".scrollIntoView(new UiSelector().textContains(\"" + text + "\").instance(0));")
}

protected MobileElement srollToElementByResourceId(String regex) {
    driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0))" +
            ".scrollIntoView(new UiSelector().resourceIdMatches(\".*" + regex + "\").instance(0));")
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.