Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check with Selenium WebDriver if a site is using Ajax?

I am doing Research and Development on few unknown third party websites to get page content using selenium.

How should I get to know whether website is Ajax based or non-Ajax based. I don't know any data inside of unknown website to check though using id or tag name, so how should I check it Ajax based or not.

like image 294
SaKol Avatar asked Nov 10 '22 13:11

SaKol


1 Answers

If I were you, I would set up a proxy and route all the WebDriver traffic thru that. In the proxy, for each request I would parse the request headers and look for header

X-Requested-With = XMLHttpRequest

Reference

If you have that, you can (with fair amount of confidence) say, that you had Ajax invoked. There may be some corner cases that you'll miss, but this should get you most of them.

Anyway, you need to consider that Ajax calls may not be done on page load, it may require user interaction to trigger those calls.

You can try to tackle it by using WebDrivers getPageSource() method and apply some method to the output looking for patterns like $.get( and $.post( and $.ajax( and all the other ones that you can come up with.

You may also be interested in this answer about setting up the proxy.

like image 136
Erki M. Avatar answered Nov 14 '22 22:11

Erki M.