Get the error code page (ex: 404, 503, 301, 302 etc.)

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
Florian
Posts: 75
Joined: Fri Jul 27, 2012 12:57 pm
Location: France (Lyon)
Contact:

Get the error code page (ex: 404, 503, 301, 302 etc.)

Post by Florian » Tue Oct 16, 2012 5:05 pm

I want to know if it is possible to get the error code of an HTML page on Ranorex?
My business need is the following one:

- on a web page, I will catch all the <ATag> and put them in a List (or anything else similar).
- For each ATag, I will perform a Click Action and check if the page works.

=> If the page work, I must have a '200 code'
=> If I get an error, I must have a 404, 503, 301 (and so on) error code.

Is it possible to catch such a code? Especially the 200 code?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Get the error code page (ex: 404, 503, 301, 302 etc.)

Post by Support Team » Wed Oct 17, 2012 12:21 pm

Hi,

There is no Ranorex specific method which will achieve this, but as you can use the .Net framework you can get the HTTPStatusCode as follows:
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(yourATag.Href);

HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();

// you can check the StatusCode of the response
if (httpRes.StatusCode==HttpStatusCode...)
{
// do something
}

httpRes.Close();
}catch (WebException webEx) {
// Now you can access webEx.Response object that contains more info on the server response
Report.Info(webEx.Message.ToString());
}
,this is just a small sample which should show you how it could work.

Regards,
Markus
Ranorex Support Team
.
Image