After using RSelenium/rsDriver for a while without issue, I recently got a very similar error message as OP, but couldn't use Docker to solve it (mostly for organizational reasons). Here's how I solved it:
Taking a look at the function documentation, it turns out that rsDriver()
is default configured to launch the Selenium server with the latest versions of both Chrome and Firefox (Gecko) drivers, even if you have specified the other browser to run. In my case, I was specifying browser = "firefox"
, but a new Chrome driver had auto-downloaded on the most recent run and, for whatever reason, wasn't playing nice with Selenium. That was the root cause of the issue.
It's not particularly intuitive, and the "Connection refused"
message doesn't really help, but following the error advice and checking the server log made me realize that Selenium was still trying to load Chrome drivers, even though I was using Firefox:
rd <- rsDriver(browser = "firefox")
# Yields an error message after doing pre/post downloads:
#> Could not open firefox browser.
#> Client error message:
#> Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Connection refused
#> Check server log for further details.
#> Warning message:
#> In rsDriver(browser = "firefox" :
#> Could not determine server status.
rd$server$log()
> $stderr
> [1] "Error: Could not find or load main class c(-Dwebdriver.chrome.driver=\"C:\filepath\to\chromedrivers\109.0.5414.25.chromedriver.exe\","
> $stdout
> character(0)
Anyway, if you specify rsDriver()
to run with either an older driver version, or just pass in NULL
so it doesn't look for a driver at all, it might fix the issue (it worked for me).
# Default parameters of the rsDriver() function:
rsDriver(port = 4567L,
browser = c("chrome", "firefox", "phantomjs", "internet explorer"),
version = "latest",
chromever = "latest",
geckover = "latest",
iedrver = NULL,
phantomver = "2.1.1",
verbose = TRUE,
check = TRUE,
...)
# Specify an older driver version you know works (or just use NULL),
# even if it doesn't correspond to the browser you're using:
rd <- rsDriver(browser = "firefox",
chromever = "109.0.5414.25") # alt: chromever = NULL
In case you're looking for the filepath that these drivers get saved to when auto-downloaded by RSelenium (e.g. maybe you want to find the name of an older driver version), on Windows, it should be ~/AppData/Local/binman
.
Shoutout to the responses on this question, which also helped point me in the right direction!