How can I scroll to the object where I'm unable to get the scrolling text?

Hi all,

I’m doing the Android mobile testing and I’m stuck in a situation where I have to scroll in the application to click on the desired object item.

As Katalon provides the scrollToText() function and here we need to pass the text then it will scroll down to that text.

But, In my case, the object hierarchy is like below:

In the above Image, You can see I’m unable to get the text of the scrolling object.

Now, Can anyone please help me with how can I scroll down to the intended scrolling object?

PS: I have tried with the help of content-desc but it didn’t work.

1 Like

Hi,

I have tried to find other methods but it seems nothing more. Let me ask my teammates if any suggestion

1 Like

Hi,

I’m struggling to scroll the element from past 2 days but unfortunately I didn’t get any solution for this :frowning_face:

1 Like

@rajan.singla I have worked this problem by creating a custom keyword of different scroll functions like scrollToObject or scrollNumberOfTimes that allows you to scroll any direction or to different types of objects. Here is an example of a scroll to object where the parameters are the direction you wish to swipe (swiping up will make the device scroll down), the path to the object in the object repository as a string, and the maximum number of times you want to scroll before returning. The function will pass if the object is within view and then you will need another command after the function is run to interact with it.

	@Keyword
	def scroll_to_Object(String objectPath, String swipeDirection, int maxScrolls ) {
		//This function will take in the object we are looking for
		// the direction of swiping (will be opposite of scroll direction)
		// and number of max scrolls before failing (each scroll about one page)
		int deviceHeight = Mobile.getDeviceHeight()
		int deviceWidth = Mobile.getDeviceWidth()
		int middleWidth = deviceWidth/2
		int middleHeight = deviceHeight/2
		int buttonPosition = 0
		int count = 0
		while (count < maxScrolls) {
			try {
				Mobile.verifyElementVisible(findTestObject(objectPath), 1, FailureHandling.STOP_ON_FAILURE)
				KeywordUtil.logInfo('Button is found')
				buttonPosition = Mobile.getElementTopPosition(findTestObject(objectPath), 2, FailureHandling.STOP_ON_FAILURE)
				if (buttonPosition < deviceHeight ){
					return
				}
			} catch (Exception ex) {
				switch (swipeDirection) {
					case 'up':
						Mobile.swipe(10, middleHeight, 10, 10)
						break
					case 'down':
						Mobile.swipe(10, middleHeight, 10, (deviceHeight-10))
						break
					case 'right' :
						Mobile.swipe(10, 10, middleWidth, 10)
						break
					case 'left' :
						Mobile.swipe((deviceWidth-10), 10, middleWidth, 10);
						break
				}
				count ++
			}

		}
		KeywordUtil.logInfo('Object not found in max amount of scrolls')
	}
2 Likes

Thanks a lot, @kreno for this function! The function runs perfectly fine. For the past 2 days, I’m struggling to find the solution to this but now this function works like a charm. Thanks a lot!

I am actually unable to understand this function. As you have mentioned:

if (buttonPosition < deviceHeight ){
return
}

In my case this condition is true, If this condition is true then how the swipe function is working to scroll down to that objectPath? Because the Mobile.swipe functions are written in the catch block.

1 Like

That is supposed to break out of the function early because the button is already on screen. If the button is already on screen then there shouldn’t be a need to scroll to it. The command after it should be the one to interact with it. The function should always succeed but may hit the max scrolls and return with the log line and will wait for the next command. So after the function is in your case it sounds like you want to tap on the object after scrolling so you would need a tap command:

scrollToObject('up', <objectPath>, <maxScrolls>)
Mobile.tap(findTestObject(<objectPath>), 5) 

If the object is not in view and you have hit the maximum amount of scrolls it will return with the log line and the next command that tries to interact with the object you are searching for will be how the test fails.

2 Likes

Yeah understood, that totally makes sense to me.
Thanks! :slightly_smiling_face:

1 Like