1

I am newbie to selenium webdriver. I am trying to validate broken images/links

Scenario:

  1. Take any sample url from any secured application which is located at different domain. Ex - footer link – Stores link : https://username:password@sample.com/some/linkOrimageUrl
  2. Execute the above url using the below code in java.

    URL url = new URL(LnkOrImgurl);
    HttpURLConnection httpURLConnect= HttpURLConnection)url.openConnection();
    httpURLConnect.setConnectTimeout(3000);
    httpURLConnect.connect(); message = ""+httpURLConnect.getResponseMessage(); System.out.println(message); httpURLConnect.disconnect();

  3. Checking the http response code – 200 – SUCCESS or 401 – UNAUTHORIZED

  4. Expected http response code - 200

But it throws me always 401- error when i execute this piece of code. Am i doing something wrong here?

Jeet
  • 5,569
  • 8
  • 43
  • 75
Baharul
  • 11
  • 2
  • Is there any proxy issue? – Abu Sufian Feb 13 '17 at 04:30
  • Following link may help you : http://stackoverflow.com/questions/6509628/how-to-get-http-response-code-using-selenium-webdriver-with-java – Abu Sufian Feb 13 '17 at 04:40
  • @abu - I tried same with apache client to validate with authenticated proxy. But no luck. HttpHost proxy = new HttpHost("165.225.104.32",80); Credentials credentials = new UsernamePasswordCredentials("C_LBaharulislam","welcome1"); AuthScope authScope = new AuthScope("165.225.104.32", 80); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(authScope, credentials); HttpClient client = HttpClientBuilder.create().setProxy(proxy).setDefaultCredentialsProvider(credsProvider).build(); HttpResponse response=client.execute(new HttpGet(LnkOrImgurl)); – Baharul Feb 13 '17 at 05:19

0 Answers0