java - Selenium 2: Detect content type of link destinations -
I am using the Selenium2Java API to interact with web pages. My question is how can I find out the content type of link sites?
Actually, this is the background: before clicking on a link, I have to make sure that the response is an HTML file, if not, I have to handle it in another way. So, suppose that there is a download link for the PDF file. Instead of opening it in the browser, the contents of that URL should be read directly.
A target must have an application that automatically knows that the existing location is HTML, PDF, XML or whatever the appropriate parser to extract useful information from documents.
Updates Added reward: This will provide me the best solution that allows me to get the content type of a given URL As Yochan suggested, how to get content types without downloading content There is a java library which can do this, especially. (The following code is Untested) The project publishes, for this it is a good example in the documentation. HTTP HEAD , and Selenium WebDrive does not seem to provide such functionality.
http client httpclient = new DefaultHttpClient (); Http head httphead = new HTTP head ("http: // foo / bar"); HttpResponse response = httpclient.execute (httphead); BasicHeader contenttypeheader = response.getFirstHeader ("content-type"); Println (contenttypeheader);
Comments
Post a Comment