Handle Ajax with Selenium RC

Posted: December 15th, 2009 | Author: | Filed under: Java Ruled, Selenium | Tags: , | 7 Comments »

Lately I have been adding improvements to the framework that I have build using selenium rc, JUnit, Java, and Xpath. While adding more functions I wanted to add a method to handle ajax. The idea was to wait until all the ajax action complete in a page. Selenium api has a waitForCondition method. Method accept a script, and time out.

1
2
public void waitForCondition(java.lang.String script,
                             java.lang.String timeout)

Our application uses Prototype ajax library. so I used

1
waitForCondition()

from selenium api, and implement the following method.

1
2
3
4
    public void waitForAjax() {
        super.waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount == 0;",
                SeleniumDefaultProperties.getResourceAsStream("default.pageload.timeout"));
    }

I have added

1
 .properties

file to handle all the server settings and timings related to our test automation framework. In above method timing is invoked from that properties file.


7 Comments on “Handle Ajax with Selenium RC”

  1. 1 Nivashini said at 9:17 pm on March 16th, 2010:

    yeah , that made so much sense! why didnt i see that!

  2. 2 Anuradha Uduwage said at 9:50 pm on March 17th, 2010:

    Sometime you don’t see what is close to…

  3. 3 Ekaterina said at 2:03 am on April 15th, 2010:

    Great! Thanks!

  4. 4 Anuradha Uduwage said at 10:21 pm on May 5th, 2010:

    Thanks for reading the blog and I am glad this post helped you…

  5. 5 uvaraj said at 6:37 am on February 15th, 2011:

    but when i use this am getting the following error

    selenium.browserbot.getCurrentWindow().Ajax undefined.

    do i have to include anything in order to make this happen..

    and one more doubt what do you mean by “Our application uses Prototype ajax library”

  6. 6 Anuradha Uduwage said at 8:21 pm on February 17th, 2011:

    Did you check if the page has ajax or not. If you use on a page that doesn’t use ajax this will obviously throw and error.

  7. 7 AM said at 1:27 pm on June 23rd, 2011:

    I was looking for this same error while searching,one of the search results is your entry. It helped me.

    Thanks,
    A


Leave a Reply

  • or, connect with
Get Adobe Flash playerPlugin by wpburn.com wordpress themes