ropensci / RSelenium

An R client for Selenium Remote WebDriver
https://docs.ropensci.org/RSelenium
341 stars 81 forks source link

makeFirefoxProfile not registering defaults #252

Closed melissagwolf closed 2 years ago

melissagwolf commented 2 years ago

Operating System: Windows 10

Selenium Server version (selenium-server-standalone-3.0.1.jar etc.): Rselenium version 1.7.7. -- R 4.0.3

Browser version (firefox 50.1.0, chrome 54.0.2840.100 (64-bit) etc.): 90.0.2

Other driver version (chromedriver 2.27, geckodriver v0.11.1, iedriver x64_3.0.0, PhantomJS 2.1.1 etc.): Not using any of these

Expected behaviour: File automatically downloaded into folder of choice

Actual behaviour: Pop up window asking me if I want to open or save file

Steps to reproduce the behaviour:

I am attempting to hundreds of csv files from a website, and I need to use makeFirefoxProfile to override the default pop-up window that asks me if I want to open or save the file. I used the following syntax:

#Set download info for remoteDriver (aka, where to save datasets)
fprof <- makeFirefoxProfile(list(browser.download.dir = "C://Users//myusername//Documents",
                                 browser.helperApps.neverAsk.openFile = "application/excel,text/csv,application/vnd.ms-excel,application/vnd.ms-excel.addin.macroenabled.12,application/vnd.ms-excelsheet.binary.macroenabled.12,application/vnd.ms-excel.template.macroenabled.12,application/vnd.ms-excel.sheet.macroenabled.12,image/png,application/zip,application/pdf",
                                 browser.helperApps.neverAsk.saveToDisk = "application/excel,text/csv,application/vnd.ms-excel,application/vnd.ms-excel.addin.macroenabled.12,application/vnd.ms-excelsheet.binary.macroenabled.12,application/vnd.ms-excel.template.macroenabled.12,application/vnd.ms-excel.sheet.macroenabled.12,image/png,application/zip,application/pdf"))

#Initiate Session
rD <- rsDriver(browser="firefox", extraCapabilities=fprof)
remDr <- rD[["client"]]

However, the profile doesn't register. The pop-up window still opens, preventing the file from downloading without my clicking on it manually, and when I do click on it manually, it goes into my default downloads folder instead.

melissagwolf commented 2 years ago

It turned out that the MIME type was not a text/csv but rather application/x-csv. Also, having the same file types for browser.helperApps.neverAsk.openFile and browser.helperApps.neverAsk.saveToDisk was contradictory. Since I wanted it to automatically save the file, I needed to only include browser.helperApps.neverAsk.saveToDisk. To find the MIME type of the file I was attempting to download, I followed these steps: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Configuring_server_MIME_types. Hope that helps someone.