Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the response headers in Selenium?

Tags:

selenium-rc

How can I get request/response logs in selenium? I have an ajax call that returns login information, and whenever I try to capture it via:

 selenium.captureNetworkTraffic("json");

it returns only client-side items (like images .pn), but not the actual JSON response I'm interested in.

like image 379
sasikumar Avatar asked Aug 16 '10 11:08

sasikumar


People also ask

How do I view response headers?

To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.

How do I view headers in selenium?

Using getText() Method To Get Heading Or Paragraph At times it becomes necessary to verify the text on the web page we are landing on. The getText() method in Selenium helps us retrieve a text and do necessary action on it.

Can we set response header?

Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.


1 Answers

Unfortunately, it doesn't look like you can do that with selenium alone in an automated fashion, as this is against their design principles for selenium. I don't agree that it is (since it supports getting cookie information -- what user actually goes through and parses through their cookies?).

Their 'schtick' is that selenium helps you automate what a user does; since a user doesn't care about the response headers, why would this framework? For me, this is disappointing because I need to ensure the content type being returned is what I believe it should be (to test an API). It appears another Stack Overflow question has come to a similar conclusion.

like image 75
George Stocker Avatar answered Oct 20 '22 13:10

George Stocker