Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've created a few WatiN Browser extension methods to solve this problem, but am still interested in other solutions.</p> <p>The <code>InjectAjaxMonitor</code> method creates a javascript global variable that attaches to the ajaxStart and ajaxComplete events to track the number of requests in progress. </p> <p>Whenever you need to wait for AJAX requests to complete before moving on, you can then call <code>browserInstance.WaitForAjaxRequest();</code>.</p> <hr> <pre><code>public static class BrowserExtensions { public static void WaitForAjaxRequest( this Browser browser ) { int timeWaitedInMilliseconds = 0; var maxWaitTimeInMilliseconds = Settings.WaitForCompleteTimeOut*1000; while ( browser.IsAjaxRequestInProgress() &amp;&amp; timeWaitedInMilliseconds &lt; maxWaitTimeInMilliseconds ) { Thread.Sleep( Settings.SleepTime ); timeWaitedInMilliseconds += Settings.SleepTime; } } public static bool IsAjaxRequestInProgress( this Browser browser ) { var evalResult = browser.Eval( "watinAjaxMonitor.isRequestInProgress()" ); return evalResult == "true"; } public static void InjectAjaxMonitor( this Browser browser ) { const string monitorScript = @"function AjaxMonitor(){" + "var ajaxRequestCount = 0;" + "$(document).ajaxSend(function(){" + " ajaxRequestCount++;" + "});" + "$(document).ajaxComplete(function(){" + " ajaxRequestCount--;" + "});" + "this.isRequestInProgress = function(){" + " return (ajaxRequestCount &gt; 0);" + "};" + "}" + "var watinAjaxMonitor = new AjaxMonitor();"; browser.Eval( monitorScript ); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload