How to download file in Selenium
Many times you need to download a file like MS Excel file, MS Word File, Zip file, PDF file, CSV file, Text file, etc.So we need to follow some steps. Manually when we click on link to download file, It will show us dialogue to save file.
Generally this dialog box is in Firefox Browser.Manually just we have to click on save file and then file will be download on particular location.But How Selenium Webdriver works
Selenium Webdriver do not have any feature to handle this save file dialogue.But Selenium can handle this dialog box and we can download any file Webdriver's has Inbuilt class FirefoxProfile and some methods.By using some methods of FirefoxProfile we can download file.
![]() |
| Firefox profile methods |
Before downloading a file in Firefox browser we should know MIME type of that file.Generally we use Mime type here
//profile.setPreference("browser.helperApps.neverAsk.saveToDisk","SpecifyMIME TYPE HERE");
If file is of pdf file then write MIME Type is application/pdf
If you have any file first find out MIME type of your file from here.Even you can google for your MIME TYPE if you don't find here.
"text/plain;" //MIME types Of text File.
"text/csv"); //MIME types Of CSV File.
Here is the code for Download File
package demodownloadfile;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
public class Downloading_File {
public static void main(String[] args) {
//Create firefox profile
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
//profile.setPreference("browser.download.dir","Specify your directory path here");
profile.setPreference("browser.download.dir","E:\\downloadfile");
//Set path where you want to download file
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword,application/x-rar-compressed,application/octet-stream,application/csv,text/csv");
//Here i have explained some MIME type
WebDriver driver = new FirefoxDriver(profile);
driver.get("http://www.winzip.com/landing/open-rar-file.html");
//Go to url
driver.findElement(By.xpath("//*[@id='downloadlink']/img")).click();
//click on file link and download file
}}
//Now your File has been Downloaded






The Blog gave me idea to download file in selenium Web Driver My sincere thanks for sharing this post Please Continue to share this kind of post
ReplyDeleteSelenium Training in Chennai
Thank you for sharing such valuable information and tips. This can give insights and inspirations for us; very helpful and informative! Would love to see more updates from you in the future.
ReplyDeleteBest selenium training in chennai
selenium Training in chennai
hp loadrunner training in chennai
Loadrunner classes in Chennai
Automation testing training in chennai
Best QTP Training Institutes in Chennai
This is a good post. This post give truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. thank you so much. Keep up the good works.
ReplyDeletePHP Training in Chennai
PHP Course in Chennai
PHP Training Institute in Chennai
PHP course
PHP Training
This comment has been removed by the author.
ReplyDeleteI am feeling great to read this.you gave a nice info for us.
ReplyDeleteplease update more.
Cloud computing Training centers in Bangalore
Cloud Computing Training in Perambur
Cloud Computing Training in Nungambakkam
Cloud Computing Training in Navalur
Thank you sharing this kind of noteworthy information. Nice Post.
ReplyDeleteArticle submission sites
Guest posting sites
I appreciate you sharing this article. Really thank you! Much obliged.This is one awesome blog article. Much thanks again.
ReplyDeleteBig Data Hadoop Training in velachery
Big Data Hadoop Training in Tambaram
Big Data Training in Tambaram
Big Data Hadoop Training in velachery
Big Data Hadoop Training in kandanchavadi
Big Data Hadoop Training in sholinganallur
Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting.
ReplyDeletePhotoshop Classes in Chennai
Photoshop Course in Chennai
Photoshop Training in Chennai
Photo Editing Courses in Chennai
Photoshop Training Institute in Chennai
Best Place to Learn Photoshop in Chennai
One of the best blogs that I have read till now. Thanks for your contribution in sharing such a useful information. Waiting for your further updates.
ReplyDeleteSpoken English Classes in Anna Nagar
Spoken English Classes in Perambur
Spoken English Classes in Ayanavaram
Spoken English Classes in Anna Nagar West
Spoken English Class in Mogappair
Spoken English Anna Nagar Chennai
Spoken English Class Anna Nagar
Spoken English Classes near me
I have to thank for sharing this blog, it is really helpful and I learned a lot from your blog.
ReplyDeleteData Science Training in Velachery
Data Science Training in Chennai Velachery
Data Science Training in Tnagar
Data Science Training in Chennai
Data Science Course in Chennai
Data Science Training in Aminjikarai
Informative blog and it was up to the point describing the information very effectively. Keep updating more post like this.
ReplyDeleteOracle Apps DBA Training in Chennai | Oracle DBA Training Institutes in Chennai | Oracle DBA Training | Oracle DBA Course in Adyar | Oracle DBA Course in Tambaram | Oracle DBA Course in Velachery