Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

The old methods of downloading a file via Selenium no longer seem to work.

My code is:

    fp = webdriver.FirefoxProfile()

    fp.set_preference("", os.getcwd())

    fp.set_preference("", 2)

    fp.set_preference("", False)



    self.driver = webdriver.Firefox(firefox_profile=fp)

    self.longMessage = True

However, the file dialog still appears. I've done quite a bit of toggling fields on and off, but after a bit of digging i found that there are no differences between the prefs.js file of a default Firefox profile generated by Selenium and the prefs.js file of one where i have manually checked "Do this automatically for files of this type from now on" on the download dialog.

The mimeTypes.rdf file does change, though—specifically, the lines below are added:

<RDF:Description RDF:about="urn:mimetype:handler:application/pdf"




<NC:externalApplication RDF:resource="urn:mimetype:externalApplication:application/pdf"/>

I don't know of a way to set up a custom mimeTypes.rdf file when creating a new Firefox Profile, though. Does anyone have any idea?

To pre-empt anyone suggesting that i just cURL the download URL, the file is generated for the user and i need to specifically verify that a .pdf file is downloaded to the drive.

1 Answer

0 votes
by (62.9k points)

I'm an R user so just posting my solution in R using RSelenium. If you are not able to convert the same in python kindly let me know I'll hint upon the same.


known_formats <- c("application/","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") <- makeFirefoxProfile(list(marionette = TRUE,                                           #this is for certificate issues [may be ignored]

                                              webdriver_accept_untrusted_certs = TRUE,

                                            webdriver_assume_untrusted_issuer = TRUE,                                             

#download related settings

                                   = 2L,

                                 = FALSE,

                                            # put your path here but remember to give path like C:\\DirOfYourChoice and not C:\\DirOfYourChoice\\ [last \\ is not going to work]

                                 = normalizePath("TestDL"),                                             browser.helperApps.alwaysAsk.force = FALSE,

                                            browser.helperApps.neverAsk.openFile = paste0(known_formats, collapse = ","),

                                          browser.helperApps.neverAsk.saveToDisk = paste0(known_formats, collapse = ","),

                               = FALSE,

#this is for marionette and related security                                          "browser.tabs.remote.force-enable" = TRUE, pdfjs.disabled = TRUE))

remDr <- remoteDriver(remoteServerAddr = "localhost",

                      port = 4444,

                      browserName = "firefox",

                      extraCapabilities =



remDr$findElement(using = "css selector", value = ".g:nth-child(1) a")$clickElement()


remDr$findElement(using = "css selector", value = ".g:nth-child(1) a")$clickElement()

Working fine with me I'm using


Firefox 50.1.0 [while I'm writing this post]

Selenium [3.0.1]

R [3.3.2 (2016-10-31)]

I hope you will be able to port this to python. Just try to replicate the configurations in firefox makeFirefoxProfile


Reference for further understanding:-

How to Download files using Selenium

Firefox Profile Settings in Selenium

Browse Categories