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:
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()