I am exploring a method to automatically scroll down a page that loads content dynamically as it is scrolled, ensuring everything is loaded before interacting with it using Selenium.
I came across this code originally written for c#, which I have converted to Java. Although the code compiles and runs, it seems to get stuck in an endless loop even after the page has fully loaded
Boolean readyStateComplete = false;
while (!readyStateComplete)
{
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("window.scrollTo(0, document.body.offsetHeight)");
readyStateComplete = (String) executor.executeScript("return document.readyState") == "complete";
}
As I am not very familiar with JavaScript, can someone help me identify what might be causing this issue?