Scroll Down not is working

I have an element that it only is visible when i scroll dowm page.

I tried with:

  • WebUI.scrollToPosition(9999999, 9999999)

  • WebUI.scrollToElement(findTestObject, rowCountryMatchRow)

  • while( WebUI.verifyElementVisible(findTestObject) == "---" ) { }

and the result continued be the same :frowning:

Error:

Web element with id: 'Object Repository/Web/.../findTestObject' located by '//select[contains(@id,'Object_Example')]' not found

Then you want to do 2 steps.

First you want to scroll to an element which is always visible and is near to the target. Then secondly you want to re-scroll to your ultimate target element.

String js = "window.scrollTo(0, 999999)"
WebUI.executeJavaScript(js, null)

window.scrollTo() takes x and y coordinates where 0, 0 is left and top.

1 Like

I do not have a problem interacting with Test Objects that are not visible until I scroll down to them as Katalon does that automatically as long as (1) the Test Object actually exists and the selector to find it is correct (2) The Test Object is actually visible (ie. the javascript method .checkVisibility() returns true). But in your case you might just want to scroll to the element, so using a method to scroll to it is required.

So with regards to the steps you have tried, I have the following comments:

This does scroll to the bottom of the page, but I have found that this does not work on our projects and each time I use this the step passes but the page still stays at the top, so it does work on a case by case basis. And this will cause you to scroll past your Test Object if the object is not at the very bottom of the page.

This method takes parameters TestObject to and int timeOut, so I am not sure what rowCountryMatchRow is, but this looks to me to be incorrect. This method does work perfectly to scroll to the Test Object and the reason why you would get element with id… located by… not found is because the TestObject literally cannot be found through the selectors it is configured with.

If I look at this while loop and the way it is written, this loop will never start. WebUI.verifyElementVisible returns a value of boolean and you are comparing it to a string thus the expression will always be false and the while loop will never start. Let’s say you do replace the expression to compare a boolean to a boolean, I would not rely on a while loop for this specific scenario. And if you got the error element with id… located by… not found when trying this step, it further proves that the Test Object cannot be found by the selectors it is configured with.

So in conclusion, I see the problem being your Test Object not being configured with the correct selectors and thus it can not be found, or the Test Object is not on the page.

Please do double check your Test Object and update it accordingly and retry using the method WebUI.scrollToElement and pass in the parameters TestObject and timeOut

ie:

//Scrolls to TestObject with timeOut set to 10 seconds
WebUI.scrollToElement(testObject, 10)

This works for me @w.alejandro

 import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')
WebUI.navigateToUrl('https://en.wikipedia.org/wiki/Main_Page')

//Scroll to bottom of page
WebUI.delay(3)
WebUI.executeJavaScript('window.scrollTo(0, document.body.scrollHeight);', null)

//Scroll to Top of page
WebUI.delay(3)
WebUI.executeJavaScript('window.scrollTo(0, -document.body.scrollHeight);', null)

//Scroll midway on page
WebUI.delay(3)
WebUI.executeJavaScript('window.scrollTo(0, 1200);', null)

//Scroll to top of page
WebUI.delay(3)
WebUI.executeJavaScript('window.scrollTo(0, 0);', null)

//Scroll to bottom of page
WebUI.delay(3)
WebUI.executeJavaScript('window.scrollTo(0, 999999);', null)

1 Like

Hi

  1. I’m agree with you, this line doesn’t show me any error, but the page still stays.

  2. I have used this method correctly, I offer you an apology that in on my example used the default parameters.

  3. in the while loop, I thought it was obvious, so I want to show you that I did it:

	int i = 0
		while( WebUI.verifyElementVisible('TestObject') == true ) {
			WebUI.delay(1)
			WebUI.executeJavaScript('window.scrollTo(0, 500);', null)
			clickObject(findTestObject,'TestObject')
			i = i+1
			if( i == 20 ) break
		}

I repeat the error NOT FOUND. If the error was the correct parameter or other things, the error would not be the same, right?

AGAIN, findTestObject is a METHOD, not a TestObject.

Someone else tried to explain this to you.

Those method calls need TestObjects!

Please read this, and the documentation, as many times as needed.

https://forum.katalon.com/t/tip-how-to-help-us-help-you/12919/37

What happens if you remain where you started on the page, open dev tools and try to find the element? Does it show in the DOM? What happens when you manually scroll down the page and look again for the xpath?
If the xpath is there the second time but not the first, you wont be able to scroll to the element, since it won’t exist in the DOM.
Any chance of a screenshot and html please?
@mwarren04011990 has given some sound advice about test objects so perhaps for your sanity try to locate the element with dev tools to guarantee it is there first!

@Dave_Evers your solution would work if you purely just want to scroll to certain parts of the page, but this is not the optimal way OP wants to scroll.

What OP is trying to do is scroll to a TestObject until it is visible. Your method of scrolling will always run the risk of scrolling past the TestObject if the page is very large, ie if the test object is found between top and midway or midway and bottom.

@w.alejandro I suggest again to double check if your TestObject is actually configured correctly and to check if it really does exists on the page, then to use WebUI.scrollToElement

1 Like

Hi @w.alejandro, If you are not familiar with manually finding/locating Web elements on a page then you should read this posting: [How To] Use The Browser Developer Tools (F12 DevTools) and this posting: [How To] Groovy(JavaScript(CSS)) - Using CSS Selectors In JavaScript In Groovy In Test Cases

You can also find lots of information here: https://www.phind.com/search?cache=87243f73-b527-4b7d-a77b-2d14cd053c6c

You can also use an Browser Extension tool like TruePath: TruePath –Ultimate Version for Chrome Browser - YouTube, (Do a Google search for truepath extension).

1 Like

Try to use page down or page up KEY

Hi @w.alejandro,
“An element is visible after scrolling down” can be an example of a Homepage header
both have the same functionally

The below code worked for me

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor
import org.openqa.selenium.WebDriver as WebDriver

WebDriver wDriver = DriverFactory.getWebDriver()
JavascriptExecutor jse = ((wDriver) as JavascriptExecutor)
jse.executeScript(‘window.scrollTo(0, 9990)’)

Hope will work for you…

Hi,

Use below code
WebUI.scrollToElement(findTestObject(‘Object Repository/div_Scrolltoelemnt’), 3)