2

Hello :) I'm trying to automate downloading spreadsheets from XYZ website. The code works well, goes through authorization without problem and downloads the file. But, when I try to change the download directory, it starts to download the file, but instantly gives me file download error in browser. The way I tried to change the download directory is by adding:

eCaps <- list(
  chromeOptions = 
    list(prefs = list("profile.default_content_settings.popups" = 0L,
"download.prompt_for_download" = FALSE,
"directory_upgrade" = TRUE,
"download.default_directory" = "C:/XXX/YYY"
    )
    )
)

and adding the extraCapabilities = eCaps to rsDrive():

rD <- rsDriver(browser= "chrome", chromever = "80.0.3987.16", extraCapabilities = eCaps)

Without these two changes code worked well, downloading to default download directory. Is there any way to set it properly to download to any other directory? Here is the complete code:

library(RSelenium)
eCaps <- list(
  chromeOptions = 
    list(prefs = list("profile.default_content_settings.popups" = 0L,
"download.prompt_for_download" = FALSE,
"directory_upgrade" = TRUE,
"download.default_directory" = "C:/XXX/YYY"
    )
    )
)
rD <- rsDriver(browser= "chrome", chromever = "80.0.3987.16", extraCapabilities = eCaps)
remDr <- rD$client

appURL <- 'https://XYZ'
remDr$navigate(appURL)
remDr$findElement("id", "loginEmail")$sendKeysToElement(list("email"))
remDr$findElement("id", "loginPassword")$sendKeysToElement(list("password", key='enter'))

appURL2 <- "https://XYZ/XYZ"
remDr$navigate(appURL2)
remDr$navigate(appURL2)

remDr$findElement("link text", "XLSX")$sendKeysToElement(list(key='enter'))
h4rves7er
  • 65
  • 6
  • 1
    From Terms and Conditions: "Except as otherwise permitted by these terms and conditions, you are not permitted to modify, copy, scrape, distribute, transmit, display, reproduce, duplicate, publish, license, frame, link, create derivative works from, transfer or otherwise use in any manner, in whole or in part, this Website or the information and materials on this Website without the prior written authorisation of WGC and with suitable accreditation to WGC. To request such authorisation, please contact us at info@gold.org." – IRTFM Feb 19 '20 at 18:10
  • @42 Thank You for your vigilance, my bad. Dispite the unfortunate website example, the problem stays actual in other future cases, can You help me? – h4rves7er Feb 19 '20 at 19:05

1 Answers1

4

I ran into this same problem and here's the solution that worked:

For some reason, you need to use double backslashes in the download.default_directory path, rather than single forward slashes.

So try this:

"download.default_directory" = "C:\\\XXX\\\YYY"

Instead of this:

"download.default_directory" = "C:/XXX/YYY"
user438383
  • 5,716
  • 8
  • 28
  • 43