How to upload files with RSelenium? How to upload files with RSelenium? selenium selenium

How to upload files with RSelenium?


The sendKeysToElement method expects a list. The path needs to be passed as a list:

library(RSelenium)appURL <- "https://www.freepdfconvert.com/pdf-word"# create sample pdftfile <- 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$clientremDr$navigate(appURL)upload_btn <- remDr$findElement(using = "id", "clientUpload")upload_btn$sendKeysToElement(list(tfile))......# cleanup when finishedrm(rD)gc()

See also the demo in the RSelenium package itself https://github.com/ropensci/RSelenium/blob/master/demo/selFileUpload.R and OpenFileDialog in R Selenium