/* javascript code in client side */ // extend jQuery ajax with the capability of remembering the count of active ajax requests $.activeAjaxRequestCount = 0; $().ajaxSend(function() { $.activeAjaxRequestCount++; // register lazily to make sure it's the last handler of ajaxError event and get executed after all production handlers if(!$._ajaxErrorHandlerAdded) { $().ajaxError(function() { $.activeAjaxRequestCount--; }); $._ajaxErrorHandlerAdded = true; } }) .ajaxSuccess(function() { $.activeAjaxRequestCount--; }); /* C# code in selenium tests */ // run this js code somehow before selenium test to turn off animation of jQuery $.fx.off = true; // an overload with 60 seconds as default timeout, this is the mostly used version public void Click(string locator) { Click(locator, 60000); } // this overload has more control on timeout public void Click(string locator, int timeout) { // decorate selenium call with waiting logic WaitComplete(() => selenium.Click(locator), timeout); } // generic decorating helper for selenium calls private void WaitComplete(Action action, int timeout) { // do default selenium action action(); // wait for active ajax request count becomes zero, none ajax selenium action will return immediately selenium.WaitForCondition("selenium.browserbot.getCurrentWindow();window.jQuery.activeAjaxRequestCount===0;", timeout.ToString()); } /* do the same trick to Select, Type, FireEvent and more selenium methods */