1

Here I Want to know webpage has AJAX calls or not. Because if webpage is AJAX based then I will wait for few seconds to get the web page contents, or else if webpage is not AJAX based then I will not wait .

I followed the below code but I didn't get any result.

WebDriver driver = new PhantomJSDriver(caps);
driver.get("http://www.airgas.com/category/Safety-Products-Clothing-WorkClothing-Acc/_/N-0Z84v");

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("$(document).ready(function() {
    $(document).ajaxStart(function(event, request, settings) {
        alert("Web Page have Ajax Calls");
    });
});
);

If I use the jQuery code which I used in javascriptexecutor in developers console I am getting alert message stating that webpage has AJAX calls or not. So is my approach is correct? If not what is the correct solution for my problem.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
prasad
  • 11
  • 3
  • "So is my approach is correct..?" --- does it work for you? – zerkms May 15 '15 at 06:59
  • This **[article](http://www.infoq.com/articles/testing-ajax-selenium)** might help you!! – Guruprasad J Rao May 15 '15 at 07:01
  • @zerkms . here jquery code is working if i put that one in developers console . . . But i want same output using above code . . There i am injecting javascript into selenium webdriver . – prasad May 15 '15 at 07:39

1 Answers1

0

looks like you're looking for this answer: How do I know if jQuery has an Ajax request pending?

with the twist you'll need to give it first some time to execute and launch the requests and only then check if any active. If any are active you can then wait till done.

HTH

Community
  • 1
  • 1
NBO
  • 103
  • 5