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
(orchrome
instead offirefox
) or in Rshell('docker pull selenium/standalone-firefox')
- start server by running in command line:
docker run -d -p 4445:4444 selenium/standalone-firefox
or in Rshell('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
How to Use R with Google Colaboratory
In 'Knitr' How to Test for If the Output Will Be PDF or Word
Convert Column Classes in Data.Table
How to Install an R Package from the Source Tarball on Windows
Remove Ids That Occur X Times R
How to Check Whether a Function Call Results in a Warning
Combining Bar and Line Chart (Double Axis) in Ggplot2
How to Get the Average (Mean) of Selected Columns
Determine the Data Types of a Data Frame's Columns
Split Up a Dataframe by Number of Rows
How to Add a General Label to Facets in Ggplot2
Count Number of Zeros Per Row, and Remove Rows with More Than N Zeros
R Compare Multiple Values with Vector and Return Vector
How to Create a Marimekko/Mosaic Plot in Ggplot2