I'm searching for a way to scroll down to a page that loads content as it is scrolled, to have everything loaded before I start interacting with it using Selenium.
I found this code below which was posted for c#, I changed it to Java. It compiles and runs. But even though the page reaches the end, it does not get out of the loop
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";
}
I don't know much about Javascript. How can this be corrected?
Please try .equals() method instead of == i means
readyStateComplete = ((String) executor.executeScript("return document.readyState")).equals("complete");
== tests for reference equality (whether they are the same object).
.equals() tests for value equality (whether they are logically "equal").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With