Can't Execute Rsdriver (Connection Refused)

can't execute rsDriver (connection refused)

Note: this answer is meant for Windows

When trying to run the deprecated checkForServer() Selenium offers two options:

  • use rsDriver
  • use Docker

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:

  • install docker
  • run it, restart computer as requested
  • pull image by running in command line: docker pull selenium/standalone-firefox(or chrome instead of firefox) or in R shell('docker pull selenium/standalone-firefox')
  • start server by running in command line: docker run -d -p 4445:4444 selenium/standalone-firefox or in R shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
  • Then run 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:

  • https://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-basics.html
  • https://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-docker.html

R Rselenium .... Failed to connect to localhost port 4444: Connection refused

The solution was to revert back to selenium-server-standalone-3.9.1.jar.

For folks trying to set this up for the first time, the steps that work for me are to run a batch file (.cmd) with the following two lines before running the R file.

java -jar selenium-server-standalone-3.9.1.jar
pause

Of course, edit the first line to match the file name as new selenium server versions release. Place the .jar file and browser drivers in a folder that's in the system search path (I edit the system path to include a custom folder that's dedicated to RSelenium related files).

When the command box pops up, you should see the following line:

07:35:53.054 INFO - Selenium Server is up and running on port 4444

My big mistake was not to double check for that line, once I returned to this with fresh eyes I realized that I should look for that line, then the solution was obvious.

Then these RSelenium commands work:

remDr <- remoteDriver(browserName = "chrome")
remDr$open(silent = TRUE)


Related Topics



Leave a reply



Submit