2

I need to download an excel-file from a database (the reason that I cannot provide code). I'm able to click on the download icon using RSelenium. What happens next is that the usual dialogue-window opens asking me if I want to save the file or open it. How can I suppress this message and download the file into a folder?

I have found a similar question regarding pdf here. The answer suggests it should be possible by specifying of the extraCapabilities:

remDr <- remoteDriver(remoteServerAddr = "localhost", 
                  browserName = "firefox",
                  extraCapabilities = someCapabilities,
                  port = 4444)

Unfortunately, I couldn't figure out how to set extraCapabilities correctly.

Can somebody hint me in a direction? Thanks for help.

Edit

I'm aware of the solution provided here and hope to be able to use the extraCapabilities-Approach.

Community
  • 1
  • 1
Thomas
  • 1,392
  • 3
  • 22
  • 38

1 Answers1

3

Here's an example:

library(RSelenium)
startServer()
remDr <- remoteDriver(extraCapabilities = makeFirefoxProfile(list(
  "browser.helperApps.neverAsk.saveToDisk"="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
))
remDr$open()
url <- "http://www.iwh-halle.de/e/fdz/IntBankLib/data/downloads/databases.xlsx"
remDr$navigate(url)
file.exists(file.path("~/Downloads/", basename(url)))
# [1] TRUE

Note that the content type has to match:

library(httr)
HEAD(url)$headers$`content-type`
# [1] "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Although you should be able to use wildcards like *.

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • the `makeFirefoxProfile(...)` command returns an error: Error in file(tmpfile, "rb") : cannot open the connection In addition: Warning messages: 1: running command '"zip" -r9Xjq "C:\Users\rockscience\AppData\Local\Temp\RtmpoPhjUb\file31028ad12f9.zip" "C:\Users\rockscience\AppData\Local\Temp\RtmpoPhjUb/firefoxprofile/prefs.js" ' had status 127 2: In file(tmpfile, "rb") : cannot open file 'C:\Users\rockscience\AppData\Local\Temp\RtmpoPhjUb\file31028ad12f9.zip': No such file or directory – RockScience Feb 17 '17 at 04:45
  • maybe because I run selenium in a docker? – RockScience Feb 17 '17 at 04:47
  • Sorry, I don't know. – lukeA Feb 17 '17 at 08:37