In my Android app, I need to scroll down the screen and validate whether the required elements(each individual element) are available or not. How do I achieve this with a Java method?
Asked
Active
Viewed 2,516 times
4
-
you can achieve scrolling by using this method: https://stackoverflow.com/questions/49233444/swipe-funtion-in-andriod-for-java-client-5-0-3-is-not-working/49233835#49233835 and after every scrolling you have validate your expected value – Al Imran Jan 07 '19 at 12:49
-
Thanks. Following your approach throws an error as "press (io.appium.java_client.touch.offset.PointOption) in TouchAction cannot be applied" – Manoj Kumar Jan 08 '19 at 08:37
-
The solution was for java-client 5.x, i'm not sure which java-client version are you using! – Al Imran Jan 08 '19 at 08:57
-
How do i check the java-client version that am using? – Manoj Kumar Jan 09 '19 at 08:32
-
You can check from `external library` folder or `pom.xml` file – Al Imran Jan 09 '19 at 08:39
-
you can try this, the solution for `java-client 6.x` http://ezyautomation.blogspot.com/2018/08/how-to-perform-vertical-and-horizontal.html – Al Imran Jan 14 '19 at 12:26
-
Thanks for sharing this and Appreciate your help. While calling the swipeVertical/SwipeHorizontal instead of giving the values and duration, is there a way where I scroll down the screen until I find a specific element? – Manoj Kumar Jan 16 '19 at 11:58
3 Answers
2
Use the following code for scrolling up and down using JAVA.
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"**Text you want to Find**\"));");
Thanks.

Nauman Malik
- 188
- 8
0
The good way here is to use native UIAutomator find strategy:
public void isElementPresent(String resourceId) {
return androidDriver.findElementsByAndroidUIAutomator("new UiScrollable(new UiSelector()
.scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId("<your app package name>:id/" + resourceId + "\"))")
.size() > 0;
}
It will scroll down & up the view to find an element by provided resourceId
and return true
if element present.

dmle
- 3,498
- 1
- 14
- 22
0
Use the following code to scroll up using java :
public void swipeUp(AppiumDriver<?> appiumDriver, MobileElement fromPosition, MobileElement toPosition) {
Dimension size = fromPosition.getSize();
Dimension size1 = toPosition.getSize();
TouchAction swipe = new TouchAction(appiumDriver)
.press(ElementOption.element(fromPosition, size.width / 2, size.height - 20))
.waitAction(WaitOptions.waitOptions(Duration.ofSeconds(4)))
.moveTo(ElementOption.element(toPosition, size1.width / 2, size1.height / 2 + 30)).release();
swipe.perform();
logger.info("Swipe Success");
}

Suraj Jogdand
- 308
- 2
- 17