title: Java SWT browser: Waiting till dynamic page is fully loaded
body: <p>I'm working with SWT browser class and I have a problem. I'm trying to copy page source from a page in which most of the data is dynamically loaded with use of ASP. The problem is that the event completed of browser event listener is of course fired before the whole page content is displayed. Here is a part of my code:</p>
  
  <pre><code>class GermaniaProgressListener implements ProgressListener {
  
    final Browser browser;
    Calendar calen;
    SimpleDateFormat dateFormat;
    static Integer counter;
    static Integer changeCounter;
    static Integer completeCounter;
  
  
    public GermaniaProgressListener(Browser browser, Calendar calen, SimpleDateFormat dateForm) {
      super();
      this.browser = browser;
      this.calen = calen;
      this.dateFormat = dateForm;
      counter = 1;
    }
  
    public void changed(ProgressEvent event) {
  
    }
  
    @Override
    public void completed(ProgressEvent arg0) {
      String pageContent = "";
      if(counter &gt; 1) {
        try {
          pageContent = (String)browser.evaluate("return document.body.innerHTML");
          FileUtilities.writeFile(
              FilePaths.GERMANIA_HTML.getFilePath().replace(".", ((Integer)(counter-1)).toString() + "."),
              pageContent);
        } catch (IOException e) {
          e.printStackTrace();
          LoggingUtilities.logException(e);
          BrowserUtilities.closeBrowser(browser);
        }
      }
      if(counter &lt; 8) {
        String strDate = dateFormat.format(calen.getTime());
        Boolean ret = browser.execute("this.controler.loadPage(0, '', 'd=" + strDate + "')");
        if(!ret) {
          LoggingUtilities.logString("Error getting germania pages");
          BrowserUtilities.closeBrowser(browser);
          return;
        }
        calen.add(Calendar.DATE, 1);
        counter++;
      } else {
        BrowserUtilities.closeBrowser(browser);
      }
    }
  };
  
  public class PageDowGermania {
    static public void getPageContent() {
      final Browser browser = BrowserUtilities.createBrowser();
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
      Calendar calen = Calendar.getInstance();
      calen.setTime(new Date());
      GermaniaProgressListener fpl = new GermaniaProgressListener(browser, calen, dateFormat);
      browser.addProgressListener(fpl);
      BrowserUtilities.startBrowser(browser, "http://www.germaniasport.hr");    
    }
  }
  </code></pre>
  
  <p>I'm not an expert in dynamic web pages so maybe someone could help me if there is any possibility for example a script in JavaScript that could check it the page is fully loaded.</p>
  
  <p>Thanks in advance</p>