RSelenium
RSelenium copied to clipboard
firefox Profile
I am using firefox and i tried to use selenium to download this file https://www.imf.org/external/np/fin/ert/GUI/Pages/Report.aspx?CU=USD&EX=CSDR&P=DateRange&Fr=628929792000000000&To=637381440000000000&CF=Compressed&CUF=Period&DS=Descending&DT=Blank
I want firefox to download the file without asking what to do with file, I edited the preferences browser.helperApps.neverAsk.saveToDisk = "application/xml", "text/xml" but it does not work....
I'm having the same issue
To download in your working directory try,
file_path <- getwd() %>% str_replace_all("/", "\\\\\\\\")
fprof <- makeFirefoxProfile(list(browser.download.dir = file_path,
browser.download.folderList = 2L,
browser.download.manager.showWhenStarting = FALSE,
browser.helperApps.neverAsk.openFile = "text/csv",
browser.helperApps.neverAsk.saveToDisk = "text/csv"))
driver = rsDriver(
port = 4857L,
browser = c("firefox"))
remDr <- driver[["client"]]
url = 'https://www.imf.org/external/np/fin/ert/GUI/Pages/Report.aspx?CU=USD&EX=CSDR&P=DateRange&Fr=628929792000000000&To=637381440000000000&CF=Compressed&CUF=Period&DS=Descending&DT=Blank'
remDr$navigate(url)
remDr$findElement(using = "xpath",'//*[@id="content1"]/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/div/table/tbody/tr[2]/td/table/tbody/tr/td[1]/small/a[1]
')$clickElement()
I think that including both of these arguments is a contraction, i.e., you're telling RSelenium to both automatically open and automatically save that same file type:
browser.helperApps.neverAsk.openFile = "text/csv",
browser.helperApps.neverAsk.saveToDisk = "text/csv"
My problem ended up being the mime types. There are thousands of different mime types that a file can be saved as. These are all of the ones I've had to add for my text/csv downloads:
fprof <- makeFirefoxProfile(list(browser.download.dir = file_path,
browser.download.folderList = 2L,
browser.download.manager.showWhenStarting = FALSE,
browser.helperApps.neverAsk.saveToDisk = "text/html,
text/html; charset=UTF-8,
text/plain,
text/csv,
text/csv; charset=UTF-8,
application/x-csv,
application/csv,
attachment/csv,
application/excel,
attachment/excel,
application/text,
application/json,
attachment/json,
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,
application/zip,
application/xhtml+xml,
application/xml,
application/octet-stream"))
Note that browser.helperApps.neverAsk.saveToDisk
instructs RSelenium to automatically save any of these file types.