download file with Rselenium & docker toolbox

前端 未结 2 740
孤城傲影
孤城傲影 2020-12-21 19:54

I m trying to download files by Rselenium but it looks impossible.I don\'t arrive to download even with an easy example:

1) i have installed docker toolbox (https:/

2条回答
  •  死守一世寂寞
    2020-12-21 20:34

    If you are using Docker toolbox with windows you may have issues mapping volumes see Docker : Sharing a volume on Windows with Docker toolbox

    If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries to auto-share your /Users (OS X) or C:\Users (Windows) directory.

    I initiated a clean install of docker toolbox on a windows 10 box and ran the following image:

    $ docker stop $(docker ps -aq)
    $ docker rm $(docker ps -aq)
    $ docker run -d -v //c/Users/john/test/://home/seluser/Downloads -p 4445:4444 -p 5901:5900 selenium/standalone-firefox-debug:2.53.1
    

    NOTE: we mapped to a directory in the Users/john space. User john is running docker toolbox

    Running the below code

    require(RSelenium)
    fprof <- makeFirefoxProfile(list(browser.download.dir = "home/seluser/Downloads"
                                 ,  browser.download.folderList = 2L
                                 , browser.download.manager.showWhenStarting     = FALSE
                                 , browser.helperApps.neverAsk.saveToDisk =  "application/zip"))
    remDr <- remoteDriver(browserName = "firefox",remoteServerAddr = "192.168.99.100",port = 4445L,extraCapabilities = fprof)
    remDr$open(silent = TRUE)
    remDr$navigate("https://www.chicagofed.org/applications/bhc/bhc-home")
    # click year 2012
    webElem <- remDr$findElement("name", "SelectedYear")
    webElems <- webElem$findChildElements("css selector", "option")
    webElems[[which(sapply(webElems, function(x){x$getElementText()}) == "2012" )]]$clickElement()
    
    # click required quarter
    
    webElem <- remDr$findElement("name", "SelectedQuarter")
    Sys.sleep(1)
    webElems <- webElem$findChildElements("css selector", "option")
    webElems[[which(sapply(webElems, function(x){x$getElementText()}) == "4th Quarter" )]]$clickElement()
    
    # click button
    
    webElem <- remDr$findElement("id", "downloadDataFile")
    webElem$clickElement()
    

    And checking the mapped download folder

    > list.files("C://Users/john/test")
    [1] "bhcf1212.zip"
    > 
    

提交回复
热议问题