Search code examples
rjsonrselenium

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


Seeking guidance on how to resolve the subject line error.

The many previous posts and solutions referenced here have already been reviewed/tried.

In the past this same error has been resolved by updating R, Rselenium, Selenium Server (selenium-server-4.1.3.jar), Java, Chrome browser, Chromedriver and/or Gecko Driver (when using Firefox). All were updated to the latest versions. Also tried Firefox. Error remains.

Windows 10 was updated/computer rebooted. No joy.

The code, which has worked for years and as recently as two weeks ago:

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

Error message and parameters:

Error in checkError(res) : 
Undefined error in httr call. httr output: Failed to connect to localhost port 4444: Connection refused 
remDr
$remoteServerAddr
[1] "localhost"

$port
[1] 4444

$browserName
[1] "chrome"

$version
[1] ""

$platform
[1] "ANY"

$javascript
[1] TRUE

$nativeEvents
[1] TRUE

$extraCapabilities
list()

What else should I examine or try?


Solution

  • 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)