There is no direct way in WebDriver to detect your ajax request. See This Problem. https://code.google.com/p/selenium/issues/detail?id=141
But I can think of work. Ask your developers to place a hidden div in the page source. Whenever they make an ajax call, ask them to update this div with a checkbox.
With WebDriver, you can easily read the flag of this Div and put your statement.
You can also use the built-in WebClient libraries present in C # or java to achieve this.
This approach is described in detail in this blog. http://www.ninthavenue.com.au/how-to-get-the-http-status-code-in-selenium-webdriver
If you just want to see if there is any ajax request, you can use the javascriptexecutor class in webDriver. see code below
IJavaScriptExecutor jsScript = driver as IJavaScriptExecutor; if(!(Boolean)jsScript.ExecuteScript("return jQuery.active == 0")) retrun "ajax request occured";
source share