How to scroll down while testing mobile apps?

While creating and executing the test cases for mobile apps i’m unable to scroll down using katalon studio. Is there any way to do that within the katalon studio?

 

Thanks,

Gaurav

1 Like

I tried above and seems to work fine with Item/Keyword *Scroll to Element*.

Thank you Hann Tran for your quick response. Much Appreciated.

Yes, it’s working with some changes in the object properties. Maybe you have to uncheck the class and check the text equals to “desired text”

You can use ‘Scroll To Text’ keyword to scroll down or up to the text you want.

Hanh Tran said:

You can use ‘Scroll To Text’ keyword to scroll down or up to the text you want.

Hanh, may i know what ‘type’ and ‘value’ are you using for this? I tried using keys.end… its not stopping.

hi,
i tried "Scroll To Text " but at time of execution it scroll down again scroll up, scroll down scroll up. as on final screen element is not present i am not able to click on element. scroll down contain about 25 elements in list. how to stop scrolling when desirable text is visible.
please help…

thanks.

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.android
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver
import io.appium.java_client.MobileElement
import io.appium.java_client.TouchAction

class 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 = ((MobileElement)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')
4 Likes
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()		}	}}The problem which i am facing is getText function is underlined which means library file is not included or code is somewere not correct, please help it out

Hi Mukul Jain,

It looks like we need to cast the listElement object to MobileElement before we can call getText:

String textItem = ((MobileElement)listElement[i]).getText()

Sorry about the confusion, and I hope this helps.

1 Like

Chris Trevarthen said:

Hi Mukul Jain,

It looks like we need to cast the listElement object to MobileElement before we can call getText:

String textItem = ((MobileElement)listElement[i]).getText()

Sorry about the confusion, and I hope this helps.

hi Chris,

can you please put whole corrected code once again. i am getting ":unable to resolve class

MobileElement" Error message once put cursor on red underlined MobileElement word.

thanks in advanced.

Hi Sanket, so sorry about that, I was missing an import. I updated my original comment near the top of this thread to include the new code with the import. There is a helpful (but somewhat hidden) feature in Katalon Studio that will auto-import any missing classes. CTRL + SHIFT + O will auto-organize your imports, adding new ones and removing unused ones.

Alternatively, if you don’t want to add Custom Keywords, I made an open source utility library that helps make a few tough functions a little bit easier in Katalon, especially scrolling. It can be included as a custom library as described in the Katalon help docs: https://www.katalon.com/resources-center/tutorials/import-java-library/

You can check out katalon-mobile-util scrolling function at: https://github.com/detroit-labs/katalon-mobile-util#scrolling

2 Likes

Hi @Chris_Trevarthen I have this problem with the custom keyword

Hi @fap

Sorry for the confusion, there should be no import after AppiumDriver at the top of your file (I think I missed a newline character). So the import for that line should just be:

import io.appium.java_client.AppiumDriver

– Chris

hi @Chris_Trevarthen, thank you very much!

1 Like

Hi @Chris_Trevarthen, I used your solution but got an error. Please help me.

hello everyone please help me i’m having this problem

I still don’t understand how to use the solution of this case that has been handled

can anyone explain with me the procedure for solving it using a short video?, or can you explain this method step by step, so that it is easy to understand?

I really need this and now I can’t take a step forward because of this problem