7

It seems this is a recurrent question, but I haven't found the solution to my problem.

I am running the following:

link <- 'https://www.google.com/'

rD <- rsDriver(verbose = TRUE,
               port=4567L, 
               browserName = 'chrome', 
               chromever = '83.0.4103.39',
               check = TRUE)
remDr <- rD$client
remDr$navigate(link)

When I run the first I get the error:

Error in wdman::selenium(port = port, verbose = verbose, version = version, : Selenium server signals port = 4567 is already in use.

I have the chrome driver in the same folder as of my R project.

How do I make this work? I have literally followed the documentation and nothing seems to work!!!

Any help would be much appreciated!

Br

Mig
  • 139
  • 2
  • 10
  • Have you tried closing the server before running the `rsDriver` function again as explained in this post? (https://stackoverflow.com/questions/43991498/rselenium-server-signals-port-is-already-in-use) – Ahorn May 22 '20 at 10:35
  • I am not sure I follow. The close command in that post is associated to the rD variable. But I cannot make the rD variable run, so how can I close the server? – Mig May 22 '20 at 10:48
  • Oh I see. The same happened to me just now. `rsDriver` threw an error and the next time I wanted to call it I got the same error as you but I couldn't close the port already in use because the `rD` object was not created. Restarting R worked for me. Or you could also just use another port (e.g., 4569L). – Ahorn May 22 '20 at 10:56
  • 1
    Restart R or you can do the following https://stackoverflow.com/a/63210964/11256262 – Allan Apr 26 '21 at 18:12

5 Answers5

6

I had this issue recently, I just assigned a random portal number i.e. port= 4837L and then reran the code and it worked fine for me. Hope it works!

ERC
  • 78
  • 3
6

I found that this worked well for me so that you don't have to keep reassigning random port numbers...

library(netstat)

rD <- rsDriver(verbose = TRUE,
               port= free_port(), 
               browserName = 'chrome', 
               chromever = '83.0.4103.39',
               check = TRUE)
Coldest
  • 135
  • 1
  • 6
4

I know this is an old question. But i think the answers here do no solve the root cause of the issue. Therefore for other readers here is my answer.

Add the following command at the end of your code, to stop the server and to release port 4567.

rD[["server"]]$stop()
BerndGit
  • 1,530
  • 3
  • 18
  • 47
1

You got two options to kill processes

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

## Option 2
system(paste0("Taskkill /F /T" ," /PID ", pid = rD$server$process$get_pid()))

These are validated in Windows. Somebody please check and review these for OSx/Unix/Linux.

ishonest
  • 433
  • 4
  • 8
-2

Doing all three of the below should cover most cases:

remDr$close()
rm(rD)
gc()
dca
  • 594
  • 4
  • 18