Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4125946
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:56:09+00:00 2026-05-20T23:56:09+00:00

I am using the Selenium 2 Java API to interact with web pages. My

  • 0

I am using the Selenium 2 Java API to interact with web pages. My question is: How can i detect the content type of link destinations?

Basically, this is the background: Before clicking a link, i want to be sure that the response is an HTML file. If not, i need to handle it in another way. So, let’s say there is a download link for a PDF file. The application should directly read the contents of that URL instead of opening it in the browser.

The goal is to have an application which automatically knows wheather the current location is an HTML, PDF, XML or whatever to use appropriate parsers to extract useful information out of the documents.

Update

Added bounty: Will reward it to the best solution which allows me to get the content type of a given URL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:56:10+00:00Added an answer on May 20, 2026 at 11:56 pm

    As Jochen suggests, the way to get the Content-type without also downloading the content is HTTP HEAD, and the selenium webdrivers does not seem to offer functionality like that. You’ll have to find another library to help you with fetching the content type of an url.

    A Java library that can do this is Apache HttpComponents, especially HttpClient.

    (The following code is untested)

    HttpClient httpclient = new DefaultHttpClient();
    HttpHead httphead = new HttpHead("http://foo/bar");
    HttpResponse response = httpclient.execute(httphead);
    BasicHeader contenttypeheader = response.getFirstHeader("Content-Type");
    
    System.out.println(contenttypeheader);
    

    The project publishes JavaDoc for HttpClient, the documentation for the HttpClient interface contains a nice example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Selenium Web Driver API with Java. Every time I want to
I am using Selenium 2 Java API with FirefoxDriver. When I fill a form,
This is probably a java noob question but here is my scenario: using selenium,
We're using Selenium with the Java API and some Javascript user extensions. We use
I'm using Selenium WebDriver with Java. I want to use Safari browser. Does Selenium
Using Selenium IDE, I am trying to locate a link within a table row.
I am currently using Selenium 2.0a2 in Java to access the Internet using an
I have searched the Selenium Webdriver APi docs hosted on google code. Currently using
So I'm using the selenium API, and am using it successfully to test on
I am using Selenium- JAVA to automate my application. In my application, when we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.