16

I can't get anywhere with R selenium. Here's the first step and my output:

library(RSelenium)
rD <- rsDriver()
# 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"
# Error in checkError(res) : 
#   Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Connection refused
# In addition: Warning message:
#   In rsDriver() : Could not determine server status.

What did I miss ?

Moody_Mudskipper
  • 39,313
  • 10
  • 88
  • 124

3 Answers3

29

Note: this answer is meant for Windows

When trying to run the deprecated checkForServer() Selenium offers two options:

  • use rsDriver
  • use Docker

see:

RSelenium::checkForServer()
# Error: checkForServer is now defunct. Users in future can find the function in 
# file.path(find.package("RSelenium"), "examples/serverUtils"). The
# recommended way to run a selenium server is via Docker. Alternatively
# see the RSelenium::rsDriver function.

Everybody seems to have issues with rsDriver and Docker is the recommended option so we'll go this route:

  • install docker
  • run it, restart computer as requested
  • pull image by running in command line: docker pull selenium/standalone-firefox(or chrome instead of firefox) or in R shell('docker pull selenium/standalone-firefox')
  • start server by running in command line: docker run -d -p 4445:4444 selenium/standalone-firefox or in R shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
  • Then run remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox'") . The doc suggests something different with a virtual machine but i couldn't get it to work.

With this I was set, here is my code:

shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox")
remDr$open()
remDr$navigate("http://www.google.com/ncr")
remDr$getTitle()
# [[1]]
# [1] "Google" 

The doc for more info:

Moody_Mudskipper
  • 39,313
  • 10
  • 88
  • 124
  • Any similiar tutorial how to start using RSelenium on Mac? – MLEN Jul 31 '17 at 18:08
  • I can't help you much unfortunately, see maybe this : https://stackoverflow.com/questions/35619490/how-can-i-start-rselenium-in-mac or this https://stackoverflow.com/questions/31948860/rselenium-in-mac – Moody_Mudskipper Jul 31 '17 at 20:06
  • You've used the same command for pulling the image and starting the server: `docker run -d -p 4445:4444 selenium/standalone-firefox` Shouldn't the first be some invocation of `docker pull` instead? (using the same command for both tasks works, though, because `docker run` pulls the image if it is not available locally). – Frank Schmitt Aug 02 '17 at 10:45
  • You're right Frank, I had made a copy and paste mistake, it's fixed, thanks. I also harmonized the use of `firefox` and `chrome` as they was some ambiguity – Moody_Mudskipper Aug 02 '17 at 11:36
  • also it seems you have one `'` too much in `browserName = "firefox'"` – Triamus Oct 18 '17 at 21:06
  • don't you mean: `system('docker run -d -p 4445:4444 selenium/standalone-firefox')` ; instead of `shell` – deann Mar 04 '18 at 11:53
  • it will have the same effect, `shell is a more user-friendly wrapper for system` from `?shell` – Moody_Mudskipper Mar 04 '18 at 12:00
  • does this mean you are running RSelenium from inside Docker? – QHarr Jul 28 '19 at 02:02
  • 3
    when I run this I get the following error ``Undefined error in httr call. httr output: Failed to connect to localhost port 4445: Connection refused`` – Nathan123 Sep 16 '19 at 16:47
3

In case that is still useful, I was running into the same problem today and was able to fix it by installing a Java Development Kit (Java SE Development Kit 11.0.1).

I was getting an error message from my computer to that effect, as well as the same R error as mentioned in this question, and it fixed it.

For a reproducible example, I was able to replicate this tutorial.

sessionInfo() R version 3.4.4 (2018-03-15) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS High Sierra 10.13.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] fr_CA.UTF-8/fr_CA.UTF-8/fr_CA.UTF-8/C/fr_CA.UTF-8/fr_CA.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RSelenium_1.7.5

loaded via a namespace (and not attached):
[1] Rcpp_0.12.17     XML_3.98-1.11    binman_0.1.1     assertthat_0.2.0 rappdirs_0.3.1   bitops_1.0-6    
[7] R6_2.2.2         jsonlite_1.5     semver_0.2.0     httr_1.3.1       curl_3.2         xml2_1.2.0      
[13] subprocess_0.8.3 tools_3.4.4      wdman_0.2.4      yaml_2.1.18      compiler_3.4.4   caTools_1.17.1  
[19] openssl_1.0.1 
1

Per the Cran vignette I had to run:

shell("docker-machine ip")

Then set the remoteServerAddr to the IP which was returned.

Quinn
  • 11
  • 1