title: Selenium WebDriver: Wait for complex page with JavaScript to load
body: <p>I have a web application to test with Selenium. There is a lot of JavaScript running on page load.<br>
  This JavaScript code is not so well written but I can't change anything.
  So waiting for an element to appear in the DOM with <code>findElement()</code> method is not an option.<br>
  I want to create a generic function in Java to wait for a page to load, a possible solution would be:  </p>
  
  <ul>
  <li>run a JavaScript script form WebDriver and store the result of <code>document.body.innerHTML</code> in a string variable <code>body</code>.</li>
  <li>compare the <code>body</code> variable to the previous version of <code>body</code>. if they are the same then set increment a counter <code>notChangedCount</code> otherwise set <code>notChangedCount</code> to zero.</li>
  <li>wait for a litte time (50 ms for example).</li>
  <li>if the page has not changed for some time (500 ms for example) so <code>notChangedCount &gt;= 10</code> then exit the loop otherwise loop to the first step.</li>
  </ul>
  
  <p>Do you think it's a valid solution?</p>