I can't get anywhere with R selenium. Here's the first step and my output:
library(RSelenium)
rD <- rsDriver()
# checking Selenium Server versions:
# BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# checking chromedriver versions:
# BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# checking geckodriver versions:
# BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# checking phantomjs versions:
# BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# [1] "Connecting to remote server"
# Error in checkError(res) :
# Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Connection refused
# In addition: Warning message:
# In rsDriver() : Could not determine server status.
What did I miss ?
Note: this answer is meant for Windows
When trying to run the deprecated checkForServer()
Selenium offers two options:
see:
RSelenium::checkForServer()
# Error: checkForServer is now defunct. Users in future can find the function in
# file.path(find.package("RSelenium"), "examples/serverUtils"). The
# recommended way to run a selenium server is via Docker. Alternatively
# see the RSelenium::rsDriver function.
Everybody seems to have issues with rsDriver and Docker is the recommended option so we'll go this route:
docker pull selenium/standalone-firefox
(or chrome
instead of firefox
) or in R shell('docker pull selenium/standalone-firefox')
docker run -d -p 4445:4444 selenium/standalone-firefox
or in R shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox'")
. The doc suggests something different with a virtual machine but i couldn't get it to work.With this I was set, here is my code:
shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox")
remDr$open()
remDr$navigate("http://www.google.com/ncr")
remDr$getTitle()
# [[1]]
# [1] "Google"
The doc for more info: