title: Scrolling down a page with Selenium Webdriver
body: <p>I have a dynamic page that loads products when the user scrolls down a page. I want to get the total number of products rendered on the display page. Currently I am using the following code to get to the bottom until all the products are being displayed.</p>
  
  <pre><code>elems = WebDriverWait(self.driver, 30).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "x")))
  print len(elems)
  a = len(elems)
  self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  time.sleep(4)
  elem1 = WebDriverWait(self.driver, 30).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "x")))
  b = len(elem1)
  while b &gt; a:
      self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
      time.sleep(4)
      elem1 = WebDriverWait(self.driver, 30).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "x")))
      a = b
      b = len(elem1)
  print b
  </code></pre>
  
  <p>This is working nicely, but <em>I want to know whether there is any better option of doing this?</em></p>