Checking HttpResponse OK (200) with Selenium WebDriver

Aniruddha picture Aniruddha · Jan 26, 2013 · Viewed 32.4k times · Source

I am using Selenium Remote WebDriver. I read all links from csv file and run test against those links. But sometimes I get 404 response.

Is there any way in Selenium WebDriver to check that we get HTTP response 200?

Answer

JimEvans picture JimEvans · Jan 27, 2013

There is no way to get HTTP status codes directly in the WebDriver API. It has been a long-standing feature request, which will likely never be implemented in the project. The correct solution to your problem is to configure your browser to use a proxy which can intercept and log the network traffic, and have your code query that proxy for he result you're after.

Of course, if all you are interested in is checking a link to make sure it returns a 200 status code, you could easily just use an HTTP client library in whatever language you desire to navigate to the link. There's no need to use WebDriver unless you need to manipulate the resulting page in some way.