katalon-studiokatalon-recorder

How can I scroll down to the end of a dynamically loading webpage?


We are talking about a webpage which as much as your scrolling down new elements coming up, up to a point.

I have try:

1.WebUI.scrollToElement(findTestObject('footer'), 30)

2.WebUI.executeJavaScript('window.scrollTo(0, document.documentElement.scrollHeight)', [])

3.WebUI.executeJavaScript('window.scrollTo(0, document.body.scrollHeight)', [])

4.WebUI.executeJavaScript(‘window.scrollTo(0, **923** )’, [])

…But none of this goes to the end of page. Any other idea?


Solution

  • I found this script which does the "job":

    try { 
      long lastHeight=((Number) WebUI.executeJavaScript("return document.body.scrollHeight", null)).longValue(); 
    
      while (true) { 
        WebUI.executeJavaScript("window.scrollTo(0, document.body.scrollHeight);", null);
        Thread.sleep(2000);
        long newHeight = ((Number)WebUI.executeJavaScript("return document.body.scrollHeight", null)).longValue();
        if (newHeight == lastHeight) { 
          break;
        } 
        lastHeight = newHeight;
      } 
    } catch (InterruptedException e) {
     e.printStackTrace();
    }