2

I am getting the following error: "Error in checkError(res) : Couldnt connect to host on http://localhost:4444/wd/hub. Please ensure a Selenium server is running."

I'm using a mac version 10.9.5, and downloaded all of the latest versions of packages and java. My code is:

library(rvest)
library(RSelenium)
library(wdman)
setwd(Path to selenium standalone file)
pJS <- phantomjs(pjs_cmd = "/phantomjs-2.1.1-macosx/bin/phantomjs")
remDr <- remoteDriver(browserName = "phantomjs")
Sys.sleep(5)
remDr$open(silent = FALSE)

And then I get the mentioned error. I've tried using the "java -jar selenium-server-standalone.jar" command in the terminal (after us the cd command to navigate to the correct directory). I've tried changing my port in the remoteDriver() function (to 4444, 5556). I've tried various Sys.sleep() times (up to 20 seconds). When I googled this error, most of the fixes were for FireFox or Windows, and not applicable to using PhantomJS

What else can I try?

jbohning
  • 55
  • 7

1 Answers1

3

The RSelenium::phantom function is deprecated. This had a pjs_cmd argument which I think you refer to above. You can use the rsDriver function from the RSelenium or the phantomjs function from the wdman package:

library(RSelenium)
rD <- rsDriver(browser = "phantomjs")
remDr <- rD[["client"]]
# no need for remDr$open a phantom browser is already initialised
remDr$navigate("http://www.google.com/ncr")
....
....
# clean up
rm(rD)
gc()

Alternatively using the wdman package

library(RSelenium)
library(wdman)
pDrv <- phantomjs(port = 4567L)
remDr <- remoteDriver(browserName = "phantomjs", port = 4567L)
remDr$open()
remDr$navigate("http://www.google.com/ncr")
...
...
# clean up
remDr$close()
pDrv$stop()
jdharrison
  • 30,085
  • 4
  • 77
  • 89
  • The second option worked for me (though the first option still gives me the same error). Thanks for your help! – jbohning Mar 23 '17 at 22:35
  • @jdharrison: when I tried your 1st option, I got this error: `"Could not open phantomjs browser. Client error message: Summary: SessionNotCreatedException Detail: A new session could not be created. Further Details: run errorDetails method Check server log for further details."`. Any idea how to fix it? Thanks! – Tung Nov 01 '18 at 22:57