title: using document.readyState correctly with Selenium
body: <p>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.</p>
  
  <p>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</p>
  
  <pre><code>        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";
          }
  </code></pre>
  
  <p>I don't know much about Javascript. How can this be corrected?</p>