RSelenium icon indicating copy to clipboard operation
RSelenium copied to clipboard

Missing vignettes for uploading and downloading files

Open MartinEden opened this issue 6 years ago • 0 comments

Hope these are useful:

Upload a file

uploadFile <- function(inputElement, path) {
    # This is because Shiny hides the native browser file upload element, and shows a more user
    # friendly one. So we first force the browser to display the hidden element.
    inputElement$setElementAttribute("style", "display: inline")
    inputElement$sendKeysToElement(list(text))
    inputElement$sendKeysToElement(list(key = "enter"))
}

Download a file

webDriver <- RSelenium::remoteDriver(
    browserName = "firefox",
    extraCapabilities = RSelenium::makeFirefoxProfile(list(
        "browser.download.dir" = "/some/path/on/your/computer/",
        # This is an enum, '2' means use the value in the browser.download.dir parameter
        "browser.download.folderList" = 2L,
        "browser.helperApps.neverAsk.saveToDisk" = "text/csv"
    ))
)

webDriver$findElement("css", "#myDownloadLink")$clickElement()
# You can then check the file is as expected by looking in the dir you set earlier

MartinEden avatar Oct 05 '18 13:10 MartinEden