简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM