简体   繁体   中英

RSelenium: Setting makeFirefoxProfile for Mac OS X to download files without asking

How should I set RSelenium Firefox profile under Mac OS X?

I tried to replicate this code (for Windows) but Firefox keeps showing me the download popup.

require(RSelenium)

my_firefox_profile <- makeFirefoxProfile(
  list(browser.download.dir = "~/Downloads/tmp",
       browser.download.folderList = "2",
       browser.download.manager.showWhenStarting = "false",
       browser.helperApps.neverAsk.saveToDisk = "text/csv/xls"))

RSelenium::startServer()
remDr <- remoteDriver(extraCapabilities = my_firefox_profile)
remDr$open()
remDr$navigate('http://www.rapidtables.com/web/html/link/html-download-link.htm')


webElem <- remDr$findElement(using = 'xpath', "//*[@id='doc']/p[6]/a")
webElem$clickElement()


remDr$close()
remDr$closeServer()

Also on RSelenium developer git repo page there's an additional way to set the browser profile

extraCapabilities <- list("browser" = "IE",
                          "browser_version" = "7.0",
                          "os" = "Windows",
                          "os_version" = "XP",
                          "browserstack.debug" = "true")
remDr <- remoteDriver$new(remoteServerAddr = ip, port = port
                          , extraCapabilities = extraCapabilities)

which I also tried with no success.

I had a similar problem with some .csv files that I was trying to download. Similarly, I had the line browser.helperApps.neverAsk.saveToDisk = "text/csv/xls")) in my code. However, Firefox saw these as binary files. Check what it says on the download window, if yours are similar then this code will work:

fprof <- makeFirefoxProfile(list(browser.download.dir = [YOUR DOWNLOAD FOLDER],
                  browser.download.folderList = 2L, 
                  browser.download.manager.showWhenStarting=FALSE,
                  browser.helperApps.neverAsk.saveToDisk = "application/octet-stream"))
remDr <- remoteDriver(extraCapabilities=fprof)
remDr$open()

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM