Thursday, September 6, 2012

Selenium WebDriver utility for determining when page has finished rendering

We are using Selenium for automated testing of our web app.   We use the new Selenium WebDriver API to create java based unit tests for interfacing with the UI.  One problem we had was determining when the page had completely finished rendering as the page may still be in the process up updating after the initial page is loaded.   There is an ADF javascript function for checking this
the helper method below can be called by the test class to determine when the page is fully synchronized with the server and the next action can be performed.

public static void waitForPageToFinishRendering(WebDriver oDriver, int timeout) {
        ExpectedCondition e = new ExpectedCondition() {
            public Boolean apply(WebDriver d) {
              JavascriptExecutor js = (JavascriptExecutor) d;
              Boolean isReady = (Boolean)js.executeScript("return AdfPage.PAGE.isSynchronizedWithServer()");
              return isReady;
          WebDriverWait w = new WebDriverWait(oDriver,

For a Good overview of using Selenium with ADF see
That article talks about using waitForElementPresent before performing the next action but I have found using the technique above to be more reliable.  Especially for complex pages where there is a lot of lazy loading going on.


  1. Good article....

  2. Great tip, thanks very much! Works way better than the kludgy alternative methods, and seems to work well consistently.

  3. Your welcome! glad it worked for you

  4. Where can i get ADF javascript?

  5. I'm not sure what it is your asking but the
    API docs can be found at

  6. We were new to selenium web driver.plz let me know the best article for beginners

    1. There are several on the project site. Start with "getting started"