As the title says, 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.
We are talking about a webpage which as much as your scrolling down new elements coming up, >>> up to a point <<<.
Letâs take it againâŚ
I open a page, and gives me 10 rows with five elements per row. Letâs say they are shoes imagesâŚ
If I scroll down, 10 more new rows with five elements per row come up. Which did not exist before!!!
If I scroll down again, 10 more new rows with five elements per row come up and so on.
Îf course at some point, where we have seen all the products, page stop scrolling.
How can I scroll automatically until I get down there?
I have found something like this:
JavascriptExecutor js = (JavascriptExecutor) driver;
try {
long lastHeight=((Number)js.executeScript("return document.body.scrollHeight")).longValue();
while (true) {
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight);");
Thread.sleep(2000);
long newHeight = ((Number)js.executeScript("return document.body.scrollHeight")).longValue();
if (newHeight == lastHeight) {
break;
}
lastHeight = newHeight;
}
} catch (InterruptedException e) {
e.printStackTrace();
}
But I donât know how to apply it in Katalon Studio!!!
Yes, I am working it in test cases folder. My problem is that I canât apply the code I added above into WebUI.executeJavaScript('', []). I have to add it as one line? It takes multi-line script? How?
First of all, I would like to apologize for the inconvenience I caused to this topic and to other users, because I wasnât able to understand Moderatorâs answer. My brain, at that particular moment, was in a state of emergency due to fatigue and I couldnât see the obvious.
About my annoyance with the supposedly funny picture with the horses posted by Moderator, I donât know⌠This is his âproblemâ, obviously a behavioral problem and Iâll let him do as he thinks.
Now, the reason I came back is to correct a small syntax error in the code in case someone else needs itâŚ
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();
}