How to upload files using RSelenium?

I am trying to figure out how to download a file using R / RSelenium. Information:

  • OS: Win 8.1, RSelenium_1.7.1, with the image of dockers (linux, standalone-chrome 3.2.0).

I tried the top comment from this SO question:

How to upload a file using Selenium WebDriver in Java

Example:

url <- "https://www.freepdfconvert.com/pdf-word"
path <- "C:/path_to_folder/filename.pdf"

remDr$navigate(url)

upload_btn <- remDr$findElement(using = "id", "clientUpload")
upload_btn$sendKeysToElement(path)

But I get the following error message:

Selenium message:java.lang.String cannot be cast to java.util.List

Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     class: java.lang.ClassCastException
     Further Details: run errorDetails method

The folder used is mapped to the virtual machine. Autoit is out of the question since it only works on Windows.

Also tried upload_btn$sendKeysToElement(list(path)), which does not return an error, but does not work.

Any help is appreciated.


Edit

I think this should work, but I see an error while viewing the screenshot:

  • default win_share
  • default sudo mkdir vm_share
  • win_share vm_share sudo mount -t vboxsf win_share vm_share. ( ssh default).
  • vm_share /home/docker/vm_share

script . (. )

library(RSelenium)

remDr <- remoteDriver(remoteServerAddr = "192.168.99.100" 
                                            , port = 4445L
                                            , browserName = "chrome"
)
remDr$open()
remDr$navigate("https://gallery.shinyapps.io/uploadfile")
webElem <- remDr$findElement("id", "file1")

# create a dummy csv 
x <- data.frame(a = 1:4, b = 5:8, c = letters[1:4])
write.csv(x, file = "testcsv.csv", row.names = FALSE)

# post the file to the app
path <- "/home/docker/vm_share/testcsv.csv"
webElem$sendKeysToElement(list(path))

remDr$close()
remDr$closeServer()

Error

+4
1

sendKeysToElement . :

library(RSelenium)
appURL <- "https://www.freepdfconvert.com/pdf-word"
# create sample pdf
tfile <- tempfile("sample", fileext = ".pdf")
pdf(tfile,width=7,height=5)
x=rnorm(100)
y=rnorm(100,5,1)
plot(x,lty=2,lwd=2,col="red")
lines(y,lty=3,col="green")
dev.off()

rD <- rsDriver()
remDr <- rD$client
remDr$navigate(appURL)

upload_btn <- remDr$findElement(using = "id", "clientUpload")
upload_btn$sendKeysToElement(list(tfile))

......
# cleanup when finished
rm(rD)
gc()

. RSelenium https://github.com/ropensci/RSelenium/blob/master/demo/selFileUpload.R OpenFileDialog R Selenium

+3

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


All Articles