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"

  7. Hi Don,

    What should I do if were facing an exception while executing the javascript to check that partial rendering of the page.

  8. You can wrap the statement in a try/catch and return something in the catch statement. Like..
    try (return AdfPage.PAGE.isSynchronizedWithServer();}
    catch(err){ return false;}

    Or return a message and handle it differently as if you landed on a non ADF page this would loop forever since there would be no AdfPage object.

  9. I have figured it out to one more low level,

    When ever I tried to check this method IsSynchronizedwithServer when the ADF page is having a protected element like TaxFileNumber/Password , the exception occurs else case it is just returning false or true.

    I have verified and the ADFpage object is defined for that page.

    The exception stacktrace of javascript executer says _textFieldField is null.

    How can we know what exactly isSyncronizedWithserver() method consists and looks for in a ADF page.more likely I wish to see the code.

    Thanks in advance and also for an immediate response.I very glad that you were following our comments after this long time.

  10. I'm no longer working on an ADF project so don't have time to investigate. You can always set a breakpoint in firebug or other javascript debugger and step through the isSyncronizedWithServer method but with the minimized function names and lack of documentation I haven't found that to be too helpful. If it gets that exception does it work if you re-call the method until it succeeds or does it continue to fail?