Take the 2-minute tour ×

I am using Selenium::Remote::Driver module for testing webpage,

Can anyone tell me how to wait for the ajax response here.

share|improve this question

2 Answers 2

For jQuery:

$driver->execute_script("return jQuery.active")

For Prototype:

$driver->execute_script("return ajax.activeRequestCount")

For Dojo:

$driver->execute_script("return dojo.io.XMLHTTPTransport.inFlight.length")

An integer will be returned, and if returned value is equal to 0, AJAX request is completed.

$count = 0;
while ($count < 20) {
    if ($driver->execute_script("return jQuery.active") == 0) {
    $count ++;

Don't know perl, so there can be some mistakes. This code will wait 20 seconds for ajax complete.

share|improve this answer


After a long browsing i got the result but not in ajax control...

I am doing some logic in code like waiting for ajax element to present in a page, This solved some of my problem. Following are the urls i referred

These links does not contain perl code, but i can do that with methods in Selenium::Remote::Driver module.

share|improve this answer
LOL, freaky c# code for waitForElementPresent instead of perl code for waiting the ajax response. Nice question and answer :) –  Aleh Douhi May 3 '12 at 14:48
I just converted the C# code into perl code by the reference of that.. –  kvysh May 4 '12 at 6:41
What you need is Explicit waits seleniumhq.org/docs/04_webdriver_advanced.html#explicit-waits. And your reference contains bad c# code. –  Aleh Douhi May 4 '12 at 15:23
This answer has completely irrelative to the question. The links given in the post has no clue for me. –  astonia Nov 30 '13 at 5:01

Your Answer


