I was using Selenium to do some SEO testing, and for political reasons the tests had to run in the Selenium IDE.
Some of the tests were for HTTP Status: certain pages should return a 301 redirect. So I was asked to find a way to extend the Selenium user-extensions.js file so that it could find the HTTP Status for a page.
At Angelblade's request, I'm posting some of the code we used to find the HTTP status of a URL. I'm not sure how much use it will be in Java though, since a lot of the processing is handled for us in the .NET objects!
It's probably not the best code, and I'm a bit hesitant about posting it, but it could at least provide a starting point for anyone else who wants to accomplish something similar.
public Int32 GetStatus(String encodedUrl)
const Int32 Request_Timeout = 90000;
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(encodedUrl);
request.Timeout = Request_Timeout;
request.AllowAutoRedirect = false;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
return (Int32) response.StatusCode;
catch (WebException webException)
if (webException.Status == WebExceptionStatus.ProtocolError &&
webException.Message == "The remote server returned an error: (410) Gone.")