RxT
RxT

Reputation: 538

RSelenium - rsDriver(browser = "firefox") -> Conection Refused

I'm trying to use Selenium for the first time in my computer. But I'm having an error in the first line:

My code:

library(RSelenium)

rD <- rsDriver(browser = "firefox")

Error message:

 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"
     Could not open firefox browser.
     Client error message:
     Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Conection Refused
     Check server log for further details.
     Warning message:
     In rsDriver(browser = "firefox") : Could not determine server status.

My OS is Linux Mint, 19.3, Cinnamon.

I installed selenium-server-standalone-3.141.59.jar and geckodriver-v0.26.0

Upvotes: 2

Views: 2103

Answers (1)

Neal Barsch
Neal Barsch

Reputation: 2940

Try this FIRST:

suppressWarnings(tryCatch(rm(remDr),error=function(e){}))
suppressWarnings(tryCatch(rD),error=function(e){}))
gc()

#relaunch
library(RSelenium)
rD <- rsDriver(browser = "firefox")
remDr <- rD$client
remDr$navigate("https://www.duckduckgo.com")

Alternatively this:

#make sure lsof is installed on your system: 
#sudo apt-get install ssh-askpass lsof

system("kill -9 $(lsof -t -i:4567 -sTCP:LISTEN)")
#might need to be run sudo depending on your system
system("sudo kill -9 $(lsof -t -i:4567 -sTCP:LISTEN)")

#relaunch
library(RSelenium)
rD <- rsDriver(browser = "firefox")
remDr <- rD$client
remDr$navigate("https://www.duckduckgo.com")

If none of that works, you may have installed the wrong geckodriver. Uninstall geckodriver from linux (sudo apt-get remove geckodriver --purge) and uninstall RSelenium from R (remove.packages("RSelenium")). Then DO NOT re-install geckodriver, but make sure you have all firefox dependencies (run sudo apt-get install firefox). Re-install RSelenium (in R), then try re-launching again without manually downloading geckodriver. In this way RSelenium will automatically download the correct geckodriver version.

Upvotes: 1

Related Questions