Rselenuim/Docker - unable to connect to remote server for firefox

85 views Asked by At

My Rselenium suddenly stopped. I looked for answers, tried all of them without any luck.I then uninstalled docker and reinstalled, restarted my machine and all of that. Finally have managed to get a piece of code working, so I know my machine is not broken.

The code that is working for me is:

library(RSelenium)

# Specify the port
port <- as.integer(4444L + rpois(lambda = 1000, 1))

# opens a new browser
cDrv3<- rsDriver(port = port,browser = "firefox",chromever = NULL, )

remDr <- cDrv3[["client"]]

remDr$navigate("https://www.google.com")
remDr$getTitle()
remDr$closeWindow()

However, this code is too cumbersome in that it downloads the browser every time and open a new browser. This makes it slow and inefficient.

What I want is to make this code work:

system("docker run -d -p 4445:4444 selenium/standalone-firefox:latest") # this part works.
remDr <<- remoteDriver(remoteServerAddr = "localhost",  browserName = "firefox", port = 4445)
remDr$open(silent = FALSE)

Currently when I run remDr$open(silent = FALSE) I get the following error:

remDr$open(silent = FALSE)
[1] "Connecting to remote server"
Error in checkError(res) : 
  Undefined error in httr call. httr output: Failed to connect to localhost port 5411 after 2260 ms: Couldn't connect to server

I have tried all of the advise on

Postgres Docker - unable to connect from remote server

can't execute rsDriver (connection refused)

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

RSelenium is not working when creating servers

Any new ideas to solve my problem?

Thanks in advance.

1

There are 1 answers

0
Ashby Thorpe On

RSelenium does not work with the latest version of Selenium. Either:

  1. Use an older version of Selenium (e.g. docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-firefox:4.8.3). You might have to experiment to find a version that RSelenium is compatible with.
  2. Use the newer selenium package, that works with the latest version of Selenium.