Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I write Tests with Selenium2/WebDriver and want to test if HTTP Request returns an HTTP 403 Forbidden.

Is it possible to get the http response status code with web driver?

share|improve this question

2 Answers

up vote 12 down vote accepted

In a word, no, it's not possible using the Selenium WebDriver API. This has been discussed ad nauseum in the issue tracker for the project, and the feature will not be added to the API.

share|improve this answer

Not sure this is what you're looking for, but I had a bit different goal is to check if remote image exists and I will not have 403 error, so you could use something like below:

public static boolean linkExists(String URLName){
    try {
      HttpURLConnection.setFollowRedirects(false);
      HttpURLConnection con =
         (HttpURLConnection) new URL(URLName).openConnection();
      con.setRequestMethod("HEAD");
      return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
    }
    catch (Exception e) {
       e.printStackTrace();
       return false;
    }
  }
share|improve this answer
1  
Handy for simple cases, but you don't have any browser state using this method (e.g. user logins). – Roger Keays Sep 6 '12 at 5:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.