OpenFileDialog in R Selenium

I am writing some tests for brilliant applications. In the UI.R data, we have fileInput-Object:

fileInput(inputId= "file", label="", accept=c(".Rdata"))

After that, click:

webEl <- remDr$findElement(using = 'css selector', "#file") webEl$clickElement()

OpenFileDialog will appear. For my test, I need to select a file with OpenFileDIalog. Is there any way to do this with R Selenium? I do not know how to do that.

+3
source share
1 answer

You need to send the name of your file to the DOM element for download. Here's an example using the Brilliant app for an example download.

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 be enough to send the file name to your web element:

webEl$sendKeysToElement(list('path/to/my/rdata.Rdata'))
+3
source

Source: https://habr.com/ru/post/1674466/


All Articles