Is it possible to retrieve http response status?

K

Khai Doan

I am using Selenium, a javascript framework for automated testing of
web application. The problem occurs when there is a server side HTTP
redirect. Selenium would detect that a new page is loaded, proceed to
the next command which then fail because the browser is carrying out
the redirect. So, is it possible to use javascript on the browser
side (Firefox 2) to get the http response status code?
 
M

Martin Honnen

Khai said:
I am using Selenium, a javascript framework for automated testing of
web application. The problem occurs when there is a server side HTTP
redirect. Selenium would detect that a new page is loaded, proceed to
the next command which then fail because the browser is carrying out
the redirect. So, is it possible to use javascript on the browser
side (Firefox 2) to get the http response status code?

If you use XMLHttpRequest to make an HTTP request then you can read out
the status and statusText properties:
http://developer.mozilla.org/en/docs/XMLHttpRequest
 
T

Thomas 'PointedEars' Lahn

Martin said:
If you use XMLHttpRequest to make an HTTP request then you can read out
the status and statusText properties:
http://developer.mozilla.org/en/docs/XMLHttpRequest

XHR handles server-side redirects transparently, so it cannot be used to
detect whether a redirect took place. The value of the status property is
either a success status code (2xx) or an error status code (4xx or 5xx)[1],
never that of a redirect (3xx).


PointedEars
___________
[1] It may be also 0 when using XHR to access the local filesystem directly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top