title: java: Sleep until website is fully loaded
body: <p>I want to open a website with selenium and extract some text via xpath. It's working but I can get the text only if I wait a few seconds until the whole website is loaded, but it would be nicer to check if the website is fully loaded. I guess I should check for any background connections (ajax calls, GETs, POSTs or whatever), what is the best way to do it? At the moment I'm trying to extract the text in a while loop (ugly solution):</p>
  
  <pre><code>WebDriver driver = new FirefoxDriver();
  driver.get("http://www.website.com");
  
  
  // Try to get text
   while (true) {
     try {
       WebElement findElement = driver.findElement(By.xpath("expression-here"));
       System.out.println(findElement.getText());
       break;
  // If there is no text sleep one second and try again
     } catch (org.openqa.selenium.NoSuchElementException e) {
       System.out.println("Waiting...");
       Thread.sleep(1000);
     }
   }
  </code></pre>
  
  <p>How would you solve this?</p>