How to scroll in a specific window which has multiple scrolls?

Hi,

I am trying to automate Instagram android app. First, I search a hashtag “#marketing” then the Instagram app shows me the list of photos. Now I want to do scroll the photos, but there are 2 scrolls on that page. I am not able to scroll where I want to scroll. I am a newbie who just started learning appium.

I would highly appreciate any sort of help.
Kind Regards
Usama

example: -> [Android- Appium]Scroll an element(android.widget.HorizontalScrollView) left , I just want to scroll the element not the screen
where:

  • “resourceIdMatches” resource-id of your scroll
  • plus you can mention direction as in example to help automator

So you mean I have to use UiScrollable? But it requires the user to specify a certain text to where we can scroll to?

What if I don’t know that text and I want to scroll for like 10 times?

just replace right part ->

try {
  // just flingForward
  driver.findElement(MobileBy.AndroidUIAutomator(
     "new UiScrollable(new UiSelector().resourceIdMatches(\"*.my_id\").scrollable(true)).flingForward()"));
} catch (Exception e) {
  // ignore
}
try {
  // or flingBackward
  driver.findElement(MobileBy.AndroidUIAutomator(
     "new UiScrollable(new UiSelector().resourceIdMatches(\"*.my_id\").scrollable(true)).flingBackward()"));
} catch (Exception e) {
  // ignore
}
try {
  // or flingToEnd but not more then 10 swipes
  driver.findElement(MobileBy.AndroidUIAutomator(
     "new UiScrollable(new UiSelector().resourceIdMatches(\"*.my_id\").scrollable(true)).flingToEnd(10)"));
} catch (Exception e) {
  // ignore
}

more commands -> https://developer.android.com/reference/androidx/test/uiautomator/UiScrollable

Not sure why but it’s not working. I think i am missing something really important. Maybe I don’t know how to identify the right scrollable element? I am stuck at this point for over 2 months, I tried to make posts in FB groups but no one willing to help. I made a 2-minute short video for you, can you please take a look at it?

I am willing to pay if you can help me solve this. I would highly appreciate your help.

Kind Regards

try exactly as written:

try {
  // or flingToEnd but not more then 10 swipes
  driver.findElement(MobileBy.AndroidUIAutomator(
     "new UiScrollable(new UiSelector().resourceIdMatches(\"*.id/recycler_view\").scrollable(true)).flingToEnd(10)"));
} catch (Exception e) {
  // ignore
}

// also try scroll when need precise scroll
try {
  // or scrollForward 3 times
  driver.findElement(MobileBy.AndroidUIAutomator(
     "new UiScrollable(new UiSelector().resourceIdMatches(\"*.id/recycler_view\").scrollable(true)).scrollForward(3)"));
} catch (Exception e) {
  // ignore
}

Didn’t work. Here is the video:

What can possibly go wrong?

Well start from inverstigate do we found elements.

System.out.println(driver.findElements(MobileBy.AndroidUIAutomator(
     "new UiSelector().resourceIdMatches(\"*.id/recycler_view\")").size());

I was able to figure it out with your help but I am not understanding how i can control swipe amount?

What does flingtoend do? Sometimes it swipes more pictures and sometimes less pictures (vertically in instagram). I am using flingtoend(10). There is not much documentations about it. can you please help?

we can try use " scrollForward()" acton. it should do ONE full scroll. and check if needed data loaded.

same thing. please see here:

:frowning:

try to execute multiple times:

driver.pressKey(new KeyEvent(AndroidKey.DPAD_DOWN));
// or
driver.pressKey(new KeyEvent(AndroidKey.DPAD_UP));

it should slowly move up or down