RSelenium: server signals port is already in use

I did not have issues until recently. What worked for me is to use the solution above and as per the solution in this thread to add a line to kill the Java instance(s) inside RStudio.

remDr$close()
rD$server$stop()
rm(rD, remDr)
gc()

system("taskkill /im java.exe /f", intern=FALSE, ignore.stdout=FALSE)

The process is composed of two parts a server (the Selenium Server) and a client (the browser you initiate). The close method of the remoteDriver class closes the client (the browser). The server also needs to be stopped when you are finished.

To stop the server when you are finished:

library(RSelenium)
rD <- rsDriver(verbose = FALSE,port=4444L)
remDr <- rD$client
remDr$close()

Now either explicitly stop the server:

rD$server$stop()

or if the rD object is removed the server will be stopped upon garbage collection:

library(RSelenium)
rD <- rsDriver(verbose = FALSE,port=4444L)
remDr <- rD$client
remDr$close()
rm(rD)
gc()

Tags:

R

Rselenium