i am writing some tests for shiny-apps. In UI.R data we have a fileInput-Object:
fileInput(inputId= "file", label="", accept=c(".Rdata"))
After i click it:
webEl <- remDr$findElement(using = 'css selector', "#file")
webEl$clickElement()
a OpenFileDialog appear. For my test i need to choose a file with OpenFileDIalog. Is there any possibility to do this with R Selenium? I have no clue how to do this.
You need to send the name of your file to the upload DOM element. Here is an example using the Shiny upload example app.
require(RSelenium)
RSelenium::startServer()
remDr <- remoteDriver()
remDr$open()
remDr$navigate("https://gallery.shinyapps.io/uploadfile")
webElem <- remDr$findElement("id", "file1")
# create a dummy csv
testCsv <- tempfile(fileext = ".csv")
x <- data.frame(a = 1:4, b = 5:8, c = letters[1:4])
write.csv(x, testCsv, row.names = FALSE)
# post the file to the app
webElem$sendKeysToElement(list(testCsv))
remDr$close()
remDr$closeServer()
So in the case of your code it would suffice to sent the file name to your webElement:
webEl$sendKeysToElement(list('path/to/my/rdata.Rdata'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With