问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/36574012/rselenium-setting-makefirefoxprofile-for-mac-os-x-to-download-files-without-ask