ScrollToText isn't working as expected

I need to do a scroll down in mobile app. Is there any way to do it excluding scrollToText. Because rather to scrolling to the text input specified, it scrolls all the way down.

Try this WebUI.scrollToPosition(0, 400)

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')

I tried this. I didn’t work for my test case :frowning:

Hi Ananth, can you provide some more details?

Are you testing an Android app or an iOS app?

What type of element are you trying to scroll to (button, text, text input field)?

Are you getting any errors in the logs?

Hi Chris,

I am testing on Android app.

The element i am trying to scroll is inside a Webview.

Earlier i was clicking on another element. Now I am clicking on another element which has a text input, and since text has to be entered the keyboard of the device pops from bottom and pushed the element to visible area which i was trying to scroll to. In this way i am clicking on that element.

Hi @Chris_Trevarthen
Can I use the same approach for iOS as well?

Hi @rdoshi,

Yes, I believe that approach will work for iOS as well.

Since writing that original post, I started work on an open-source library to help with common functions, like scrolling. You can view the section on scrolling here:

You can see more about installing this library here:

Hope this helps,

Chris

Hi @Chris_Trevarthen

Thanks for your reply! It actually worked! I’m able to scroll the screen now.
However, when scrolling action is complete it is not able to identify next action. It gets stuck.

My Script -->
Scroll.scrollListToElementWithText(‘Regression - COB/XCUIElementTypeStaticText - Certify’,
0)

Mobile.tap(findTestObject(‘Regression - COB/XCUIElementTypeStaticText - Certify’), 0)

At the end, I’m getting below Error

Reason:
com.detroitlabs.katalonmobileutil.exception.ListItemsNotFoundException:
Could not find any list elements matching xpath: //*[@type=‘XCUIElementTypeStaticText’ and @visible=‘true’]
and that exactly one label has the text: ‘Regression - COB/XCUIElementTypeStaticText - Certify’
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollEntireList(Scroll.java:236)
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithXPath(Scroll.java:193)
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:131)
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:86)
at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:65)
at com.detroitlabs.katalonmobileutil.touch.Scroll$scrollListToElementWithText.call(Unknown Source)
at Regression - COB.run(Regression - COB:59)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1581534997777.run(TempTestCase1581534997777.groovy:23)

Could you please help?

Hi @rdoshi,

If I recall, the first argument to the scrollListToElementWithText function should just be the text you’re looking for, so in your case, the call might be:

Scroll.scrollListToElementWithText('Certify',0)

The function will automatically scroll through all of the text elements on the screen to look for that text.

Hope this helps,

Chris

Hi @Chris_Trevarthen

I tried what you have suggested and it is still giving the same Error and not executing “Browse” tap task after Scrolling.

Script -->

Scroll.scrollListToElementWithText(‘correct’, 0)

Mobile.tap(findTestObject(‘Regression - COB/XCUIElementTypeButton - Browse’), 0)

Reason:

com.detroitlabs.katalonmobileutil.exception.ListItemsNotFoundException:

Could not find any list elements matching xpath: //*[@type=‘XCUIElementTypeStaticText’ and @visible=‘true’]

and that exactly one label has the text: ‘correct’

at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollEntireList(Scroll.java:236)

at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithXPath(Scroll.java:193)

at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:131)

at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:86)

at com.detroitlabs.katalonmobileutil.touch.Scroll.scrollListToElementWithText(Scroll.java:65)

at com.detroitlabs.katalonmobileutil.touch.Scroll$scrollListToElementWithText.call(Unknown Source)

at Regression - COB.run(Regression - Health - Self Claim without COB:57)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1581539417271.run(TempTestCase1581539417271.groovy:23)

Hi @rdoshi,

Could you send a screenshot of what you’re seeing on the screen after the scrolling completes? Have you used the Mobile Spy tool in Katalon? I’d like to see what all of the detected elements are on the screen are, if you could provide a screenshot of Mobile Spy?

Thanks,

Chris

Hi @Chris_Trevarthen

Let me know if anything else is required.

Thanks!

Thanks @rdoshi,

I was hoping to see the screen that you get from the Spy Mobile view (using this icon: Screen Shot 2020-02-12 at 6.10.49 PM )

That way I can get an idea of how the screen is laid out and hopefully the properties of the elements you’re trying to interact with, like this:

Thanks,

Chris

Hi @Chris_Trevarthen

Sorry for misunderstand!

Here is a screenshot where I’m currently at “Yes” button and after that I’m performing Scrolling to go down to tap on Submit button.

Properties of Submit Button →

Hi @rdoshi,

Thanks for the screenshot. From the error that you mentioned above, it looks like your script:

Scroll.scrollListToElementWithText(‘correct’, 0)

Is scrolling the screen, but not able to find a text element with the text “correct” - that’s what the stack trace says, anyway. Can you confirm that there is a static text element labeled “correct” on the screen? If that’s not the label, then you might need to update that line of your test script with the actual label value.

— Chris

Hi @Chris_Trevarthen

Thank You So Much for your help!
Actually, the “correct” word was enclosed with a sentence and that was the reason it was not identifiable.
When I input the entire sentence with Scroll.scrollListToElementWithText, it worked!

Thanks again!
Have a great weekend :slight_smile:

1 Like

Hi @Chris_Trevarthen, i tried with your code and got this error, please help me to resolve it.!

Hi
I cant use this command to scroll in a form!
i want to scroll down in form and fill the information.
please help me .

please take a look to this