Unable to scroll down text using scrollToText

Chris Trevarthen said:

I found that Mobile.scrollToText(‘My Label’) didn’t work well on Android when the drop down list was longer than one screen. It would scroll a bit, then stop, never finding my required item.

To get around this, I had to extend Katalon by creating a Custom Keyword to handle scrolling - this relies on the AppiumDriver library (thanks to Nhi Dinh for the sample code):

Create a new keyword file:

package com.my.keywords.androidimport com.kms.katalon.core.annotation.Keywordimport com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactoryimport io.appium.java_client.AppiumDriverimport io.appium.java_client.TouchActionclass swiping {	AppiumDriver driver;	swiping() {		this.driver = MobileDriverFactory.getDriver()	}	private scrollEntireList() {		// very specific to android and the type of element that makes up your dropdowns		ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView")		TouchAction touchAction = new TouchAction(driver)		def bottomElement = listElement[listElement.size() - 1]		def topElement = listElement[0]		// Press and scroll from the last element in the list all the way to the top		touchAction.press(bottomElement).moveTo(topElement).release().perform();	}	@Keyword	def boolean scrollListToElementWithText(String elementText) {		boolean isElementFound = false;		while (isElementFound == false) {			// very specific to android and the type of element that makes up your dropdowns					ArrayList listElement = driver.findElementsByClassName("android.widget.CheckedTextView")			for (int i = 0; i<listElement.size(); i++) {				String textItem = listElement[i].getText()				if (textItem == elementText) {					isElementFound = true;					return true;				}			}			scrollEntireList()		}	}}

  
Then in your test, you can use the Custom Keyword like:  
  

CustomKeywords.‘com.my.keywords.android.swiping.scrollListToElementWithText’(‘My Label’)


  

  

Hi Chris,

This is same
passes on katalon’s log, but the app can’t scrolling