Handle Ajax with Selenium RC
Posted: December 15th, 2009 | Author: Anuradha Uduwage | Filed under: Java Ruled, Selenium | Tags: Java, Selenium | 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.


yeah , that made so much sense! why didnt i see that!
Sometime you don’t see what is close to…
Great! Thanks!
Thanks for reading the blog and I am glad this post helped you…
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”
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.
I was looking for this same error while searching,one of the search results is your entry. It helped me.
Thanks,
A