title: Test dynamically loaded content with Selenium Web Driver
body: <p>I am working on a system that has a web based frontend that I am testing with Selenium. On one page the content is dynamically loaded when scrolling down (maybe you know that from Facebook's friend-list), because it is one of the requirements.</p>
  
  <p>Scrolling down with Selenium Webdriver (I use Chrome) should be no problem via Javascript. But there is a problem with the dynamically added content. How can I make the Webdriver find those elements?</p>
  
  <p>I tried the following to scroll down until no more content is loaded:</p>
  
  <pre><code>int oldSize = 0;
  int newSize = 0;
  do {
    driver.executeScript("window.scrollTo(0,document.body.scrollHeight)");
    newSize = driver.findElementsBy(By.cssSelector("selector").size();
  } while(newSize &gt; oldSize);
  </code></pre>
  
  <p>But though the page scrolls down the first time and some now content is loaded correctly, they will not be found by the drivers' findElementsBy(By) function.</p>
  
  <p>Has someone ever faced this problem?? I'd be very glad if someone could help me figuring a solution for that!</p>
  
  <p>Regards, Benjamin</p>