Getting HTTP status code from Selenium WebDriver C #

I use Selenium, C #, NUnit to write automated tests.

Can I get an HTTP status code using WebDriver so that tests that fail because of HTTP requests can be alerted to the user?

+7
c # selenium nunit selenium-webdriver
source share
2 answers

Not without an external tool, no.

You see, this was several times in the past and is one of the biggest "problems" in the official Selenium tracker store. the particular problem was rejected and essentially decided that it went beyond Selenium.

This, however, does not mean that it is impossible. Fortunately, you are using C #, so this is a little easier than you think.

Recently, one of the developers of Selenium wrote a blog post describing how to do this in C # . This is a three-part blog post that will help explain each step and uses an external tool called Fiddler (which, by the way, is one of the amazing tools).

Fiddler is a proxy server and has a C # API that allows you to intercept requests. This means that you can simply β€œtell” Selenium to use this proxy server and then connect to the Fiddler API to see exactly what status code the request has.

I am simply attached to a blog post, and not providing you with the code because it is explained in some detail in these posts.

Perhaps try and then come back if you have problems with its design. By the way, the guy is also a member here at StackOverflow, so he can also see your message.

+6
source

This is not ideal, but I am comparing the text of the page with the following regular expression, since in my installation the text accompanies the errors of the web page:

(?:(access is denied)|(access is forbidden)|(server error)|(not found)) 
0
source

All Articles