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
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 @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
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
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
Thanks @rdoshi,
I was hoping to see the screen that you get from the Spy Mobile view (using this icon: )
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
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
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
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 .