Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking HttpResponse OK (200) with Selenium WebDriver [duplicate]

Tags:

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?

like image 273
Aniruddha Avatar asked Jan 26 '13 13:01

Aniruddha


People also ask

Can we get the HTTP response code in Selenium with Java?

We can get the HTTP response code in Selenium webdriver with Java. Some of the response codes are – 2xx, 3xx, 4xx and 5xx. The 2xx response code signifies the proper condition, 3xx represents redirection, 4xx shows resources cannot be identified and 5xx signifies server problems.

How does Selenium handle session expiration?

If Current time - Test start time >= 30 minute s then check if system logout and if yes then login again. but for this question is same like I have to call it in either every method or in some specific methods to check every time if logout or not.


1 Answers

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.

like image 153
JimEvans Avatar answered Sep 22 '22 14:09

JimEvans