How to stop scrolling when certain text or element is found

Hi, I am a beginner in appium. While scrolling, I want to stop scrolling when certain text or element is encountered.
I’ve tried several times by referring to the appium documentation, but I’m running into problems.

  1. On long screens, scrolling does not go all the way to the end of the screen and stops in the middle.
  2. Scrolling doesn’t stop when it finds text.
  3. “setMaxSearchSwipes(10)” doesn’t seem to work.
  4. Action results do not match.
    ex) scroll range

Below is the code I used. Note please.

MobileElement Element = driver.findElement(MobileBy.AndroidUIAutomator(
				"new UiScrollable(new UiSelector().scrollable(true)).setAsVerticalList().setMaxSearchSwipes(10)" +
		         ".scrollIntoView(new UiSelector().text(\"my_text\"))"));

please help thank you

1 Like

To scroll, I use Mobile Command provided by UiAutomator2.

HashMap<String, Object> parameter = new HashMap<>();
parameter.put(“elementId”, ((RemoteWebElement) webElement).getId());
parameter.put(“direction”, direction);
parameter.put(“percent”, 1.0);
parameter.put(“speed”, 15000);
((JavascriptExecutor) getAppiumDriver()).executeScript(
“mobile: scrollGesture”, parameter
);

First of all, thanks for the reply, but I’m using Java. The code you provided is not recognized.

The shared code snippet is in Java. if you concerns is related to getAppiumDriver(). then replace this with driver.

HashMap<String, Object> parameter = new HashMap<>();
parameter.put(“elementId”, ((RemoteWebElement) webElement).getId());
parameter.put(“direction”, direction);
parameter.put(“percent”, 1.0);
parameter.put(“speed”, 15000);
((JavascriptExecutor) driver).executeScript(
“mobile: scrollGesture”, parameter
);