title: Puppeteer - scroll down until you can't anymore
body: <p>I am in a situation where new content is created when I scroll down. The new content has a specific class name.</p>
  <p>How can I keep scrolling down until all the elements have loaded?</p>
  <p>In other words, I want to reach the stage where if I keep scrolling down, nothing new will load.</p>
  <p>I was using code to scroll down, coupled with an</p>
  <pre><code>await page.waitForSelector('.class_name');
  </code></pre>
  <p>The problem with this approach is that after all the elements have loaded, the code keeps on scrolling down, no new elements are created and eventually I get a timeout error.</p>
  <p>This is the code:</p>
  <pre><code>await page.evaluate( () =&gt; {
    window.scrollBy(0, window.innerHeight);
  });
  await page.waitForSelector('.class_name');
  </code></pre>