Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appium - How to scroll down using UiAutomator2 and WebdriverIO with React Native (Android) and JavaScript

No matter what I try, I am unable to get my React Native (Android) app to scroll down using Appium.

I am using UiAutomator2 and WebdriverIO.

My code looks like this:

scrollUntilDisplayed(element: WebdriverIO.Element) {
    const dimensions = driver.getWindowSize();
    touchScroll(10, 100);
}

In place of touchScroll, I have tried the following calls:

  • driver.touchScroll(offsetX, offsetY) - throws an error (invalid argument: java.lang.IllegalArgumentException: ScrollToModel: The mandatory field 'params' is not present in JSON)
  • driver.touchScroll(offsetX, offsetY, element) - throws an error (invalid argument: java.lang.IllegalArgumentException: ScrollToModel: The mandatory field 'params' is not present in JSON)
  • browser.execute("mobile: scroll", {direction: 'down'}); - throws an error (unknown error: An unknown server-side error occurred while processing the command. Original error: Both strategy and selector arguments must be provided)
  • driver.touchFlick(0, dimensions.height, undefined, 10000, 10000, 10000); - does nothing; sits until Appium times out
  • element.scrollIntoView(); - does nothing
like image 503
Smoogy Avatar asked Jul 21 '26 11:07

Smoogy


1 Answers

Since ReactNative has a NATIVE_APP context (as a regular Android app) you can use uiautomator selector:

const bottomElementSelector = `new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text("Element label text"))`
const bottomEl = $(`android=${bottomElementSelector}`)

Search for an element with srollable selector should move focus down to that element

Note: Make sure you are using UiAutomator2 in Appium capabilities

like image 192
dmle Avatar answered Jul 23 '26 02:07

dmle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!