ScrollToText in mobile app is not working

I am experiencing an issue with scrolling down a mobile page to locate a specific element or text. Instead of scrolling down, Katalon is trying to scroll up when I use the ScrollToText function. The script was working fine for me last week, but it stopped functioning correctly on Wednesday and Thursday. I’m currently stuck and would appreciate any help from the group to resolve this scrolling issue. I am attaching a video for you to look over. Thank you in advance!

This is the script I am using for scrolling which was working earlier

Mobile.verifyElementExist(findTestObject('Object Repository/Mobile App/Home condosed screen/android.view.ViewGroup (2)'), 0)
Mobile.waitForElementPresent(findTestObject('Object Repository/Mobile App/Home/android.widget.TextView - Complete Additional Tasks'), 0)
Mobile.scrollToText('Complete Additional Tasks')
Mobile.tap(findTestObject('Object Repository/Mobile App/Home/android.widget.TextView - Complete Additional Tasks'), 0)
Mobile.scrollToText('Tenderness & Swelling')
1 Like

What happens when you change all your “timeOut” parameter on your statements from 0 to 5 or 10 and then try again. I personally have 10. I have read somewhere that when Katalon sees 0 in the “timeOut” parameter, it changes it to 30, but I don’t remember if it did it for everything or just the one I was investigating. So, change it so you know what it is and try again. Think of it like you are trying to snap your fingers. You always fail in 0 seconds, you might pass in 1 second, but easy in 5 seconds.

1 Like

Solutions to resolve the Mobile.scrollToText() issue in your Katalon mobile script:

1. Check for UI Changes in the App

If the layout of the app has changed (e.g., new elements added, existing elements repositioned), scrollToText may behave unexpectedly. Verify the current UI structure using Appium Inspector or Katalon Spy Mobile Utility.

2. Use Mobile.swipe() for Directional Control

Replace scrollToText with explicit swiping to control scroll direction:

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
// Get the driver instance
def driver = MobileDriverFactory.getDriver()
// Define swipe coordinates (adjust percentages based on screen size)
int startX = 50 // 50% of screen width
int startY = 80 // Start swipe from bottom 80% of screen
int endY = 20   // Swipe to top 20% (scrolls down)
int swipeDuration = 1000 // Milliseconds
// Swipe until text is found
int maxAttempts = 5
for (int i = 0; i < maxAttempts; i++) {
    if (Mobile.verifyElementExist(
        findTestObject('Your_Text_Object'), 
        1, 
        FailureHandling.OPTIONAL
    )) {
        break
    }
    Mobile.swipe(startX, startY, startX, endY, swipeDuration)
}

3. Specify Scrollable Container

If your text is inside a specific scrollable layout (e.g., RecyclerView), explicitly target it:

Mobile.scrollToText(
    'Complete Additional Tasks',
    [:],
    findTestObject('Object Repository/Scrollable_Container_Object'),
    10 // Timeout
)

4. Use Appium’s UiScrollable Strategy (Android Only)

Add this capability to your Android desired capabilities:

"appium:automationName": "UiAutomator2",
"appium:enableMultiWindows": false,
"appium:ignoreUnimportantViews": true

Then use:

Mobile.tap(findTestObject('Object Repository/...'), 0)
Mobile.swipe(0, 0, 0, 0, FailureHandling.STOP_ON_FAILURE) // Workaround for stale elements

5. Alternative: TouchAction API

import io.appium.java_client.TouchAction
import io.appium.java_client.touch.offset.PointOption
def driver = MobileDriverFactory.getDriver()
// Get screen dimensions
int screenWidth = driver.manage().window().size.width
int screenHeight = driver.manage().window().size.height
// Calculate swipe points (adjust as needed)
int startY = (screenHeight * 0.8) as int
int endY = (screenHeight * 0.2) as int
new TouchAction(driver)
    .press(PointOption.point(screenWidth/2, startY))
    .waitAction()
    .moveTo(PointOption.point(screenWidth/2, endY))
    .release()
    .perform()

6 Logs & Troubleshooting

  1. Check Katalon Logs: Look for [WARN] or [ERROR] messages during scrolling.
  2. Appium Server Logs: Verify if Appium is throwing UiObjectNotFoundException or StaleElementReferenceException.
  3. Video Analysis: If the video shows rapid scroll attempts, add delays between swipes:
Mobile.delay(2) // 2-second pause between swipes

Why This Happens

  • Layout Changes: Dynamic content (e.g., loading states) can alter scrollable regions.
  • Framework Updates: Appium/Katalon updates may change scroll behavior (e.g., UiAutomator2 vs. legacy).
  • Screen Density Variations: Swipe coordinates may need adjustment for different devices.