views:

623

answers:

2

I'm trying to get Selenium to wait for all of the AJAX requests on a page to complete before proceeding to the next command. I'm using wait_for_condition and the following JavaScript:

function(){
  var wait = function() { return jQuery.active == 0; }
  return wait.call(selenium.browserbot.getCurrentWindow());
}();

This works fine in Firefox but fails with a timeout in IE.

Does anyone know why this might be or have an alternative approach for waiting for AJAX requests to finish?

A: 

How about just using this simplified version:

selenium.browserbot.getCurrentWindow().jQuery.active == 0;

Sounds stupid, but most of the IE problems are solved in that way...

If this doesn't work, you can analyze another alternative: http://www.markhneedham.com/blog/2009/05/14/selenium-waiting-for-jquery-ajax-calls/ But I would live it as the last plan, as modifying jquery to keep a counter of the ajax calls at the moment sounds a little like an overkill...

Santi
A: 

I've found this advice on many blog posts, but mysteriously no one tells where this "selenium.browserbot.getCurrentWindow().jQuery.active == 0;" is supposed to go. It doesn't work if I put it into the "waitForCondition" parameter in the IDE. I'm guessing it should go into user-extensions.js, but not as an anonymous function. I've tried putting this in that file:

function wait_for_ajax(timeout){
  return selenium.browserbot.getCurrentWindow().jQuery.active == 0;
};

but it seems like a no-op (the following tests still fail).

Jean Jordaan