Can I Scroll to a Specific Element (Not Just Text) in Mobile Automation?

Hi everyone,

In my mobile automation script using Katalon Studio, I want to scroll to a specific element, not just by text using Mobile.scrollToText().

Is there a way to scroll directly to a TestObject or element itself (e.g., by resource-id or XPath), especially when I know the object but it’s currently off-screen?

Any suggestions or code examples would be really helpful.

Thanks in advance!

1 Like

Hi @mandeep.singh1,

Great concern. Yes, you can scroll directly to an element (TestObject) by its XPath or resource-id using Katalon Studio for mobile automation.

Since Mobile.scrollToText() isn’t ideal when you need to scroll by a TestObject directly, you’ll generally use something like a looped scroll function or the built-in method with a custom scroll approach.

Sample approach using Mobile.scrollToElement:

Mobile.scrollToElement(TestObject to, int timeout)

Example usage:

// Your defined TestObject, using XPath or resource-id
TestObject targetElement = findTestObject('path/to/your/object')

// Scroll to the element with a timeout (e.g., 10 seconds)
Mobile.scrollToElement(targetElement, 10)

// Verify the element is visible or clickable after scrolling
Mobile.verifyElementVisible(targetElement, 10)

In cases where built-in methods don’t always work reliably, you can implement a custom scroll loop, using a combination of Mobile.swipe() and Mobile.verifyElementExist(). Customize the swipe coordinates (Mobile.swipe(startX, startY, endX, endY)) according to your app’s specific scrolling behavior and device resolution.

Hope this can help

I dnt have any method name Mobile.scrollToElement ? What should i do

to scroll to a specific element (not just by text) in Katalon Studio for mobile automation, even if Mobile.scrollToElement() is unavailable in your version:


1. Use a Custom Scroll Function with Swipe Gestures

If Mobile.scrollToElement() isn’t available, implement a loop that swipes until the element is found:

groovy

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

// Define your TestObject (e.g., by XPath or resource-id)
TestObject targetElement = findTestObject('Object Repository/btnSubmit')

// Custom scroll function
boolean elementFound = false
int maxAttempts = 5
int swipeDuration = 2 // seconds

for (int attempt = 0; attempt < maxAttempts; attempt++) {
    try {
        // Check if the element is already visible
        if (Mobile.verifyElementVisible(targetElement, 1)) {
            elementFound = true
            break
        }
    } catch (Exception e) {
        // Swipe up (adjust coordinates for your device)
        Mobile.swipe(50, 70, 50, 30, swipeDuration)
    }
}

if (!elementFound) {
    throw new Exception("Element not found after ${maxAttempts} scroll attempts")
}

// Proceed with the element
Mobile.tap(targetElement, 10)

2. Use XPath or Resource-ID with Mobile.verifyElementVisible

If you know the element’s exact locator (e.g., resource-id), use it directly after scrolling:

groovy

TestObject targetElement = findTestObject('btnSubmit', [('resource-id') : 'com.app:id/btnSubmit'])

// Combine with a swipe loop (as in Step 1)

3. Leverage Appium’s UiScrollable (Android Only)

For Android, use UiAutomator syntax in a Mobile Call Test Case:

groovy

Mobile.callTestCase(
    findTestCase('YourTestCase'),
    [
        ('strategy') : 'android uiautomator',
        ('selector') : 'new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().resourceId("com.app:id/btnSubmit"))'
    ]
)

4. Update Katalon Studio

groovy

// Syntax for Katalon 7.0+
Mobile.scrollToElement(targetObject, timeout)

5. Adjust Swipe Coordinates

Customize swipe start/end points based on your app’s layout:

  • Android/iOS:

groovy

// Vertical scroll (swipe from 70% to 30% of screen height)
Mobile.swipe(startX, startY, endX, endY, duration)

Example coordinates for a 1080x1920 device:

  • startX: 500, startY: 1500, endX: 500, endY: 500

Troubleshooting Tips

  • Use Mobile.delay(1) between swipes if the UI is slow to render.
  • Pair with Mobile.waitForElementPresent(targetObject, 30) to avoid infinite loops.
  • For iOS, use Mobile.swipe(0, 500, 0, 200) (adjust based on screen size).

By combining swipe gestures with locators (XPath, resource-id), you can reliably scroll to off-screen elements even without Mobile.scrollToElement()