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
- Check Katalon Logs: Look for
[WARN]
or [ERROR]
messages during scrolling.
- Appium Server Logs: Verify if Appium is throwing
UiObjectNotFoundException
or StaleElementReferenceException
.
- 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.