The best way to inspect HTTP response headers with Selenium [closed] The best way to inspect HTTP response headers with Selenium [closed] selenium selenium

The best way to inspect HTTP response headers with Selenium [closed]


captureNetworkTraffic() API in DefaultSelenium captures http request/response headers and you can access them in html/xml/plain format.

Here is sample code:

Selenium s = new DefaultSelenium(...);s.start("captureNetworkTraffic=true");s.open("http://www.google.com");String xml = s.captureNetworkTraffic("xml"); // html, plains.stop();


I've answered this question a couple times on StackOverflow. Search my previous answers to dig it up. The key that you have to write some custom Java code that extends ProxyHandler and SeleniumServer. You also need to use a release AFTER 1.0 beta 2.

As to the people who ask why you'd want to do this: there are a lot of reasons. In my case, we're testing an AJAX heavy app and when things go wrong, one of the first things we debug is the network wire. That helps us see if the AJAX call happened and, if so, what the response was. We're actually automated the collection of this info and capture it (along with a screenshot) with every Selenium test.


I would not use Selenium for this type of test and suggest that you solve a variety of testing issues with different tools. what we do is:

  • Use unit tests to test code: methods and classes

  • Integration tests to test how application components hang together

  • A Simple functional test framework like Canoo WebTest (or some equivalent) to assert things like Http cache headers, basic page structure, simple redirection and cookie setting / values

  • Bespoke tests to ensure validity of pages to W3C standards

  • JSunit to test Javascript classes and methods we created

  • Selenium to test UI functionality/behaviour and the integration of Javascriptinto those pages

Its worth spending time breaking out the responsibility of testing different aspects of the system using these different tools since using only Selenium can cause issues:

  • The bigger the suite, the slower they run. Indeed Selenium is inherently slower compared to the other tools mentioned
  • It handles behaviour/functional testing well but nevertheless XPaths can be brittle and may require increasing amounts of time and effort to maintain
  • Usually requires you setup 'as-if-real-life' data with your app to step through user scenarios (which can be messy and take a lot of time)

There are also some techniques - which you may or may not have come across - which you can use to make your Selenium tests more resilient.