Using Rselenium on mac sierra

ぐ巨炮叔叔 提交于 2019-12-12 10:19:48

问题


It seems that every time I update my OS, R, or any browsers Rselenium stops working. I can no longer use it with any browser -Firefox, Chrome, or PhantomJS. I've posted my code below.

Session Info:

sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.2

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

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

other attached packages:
[1] rvest_0.3.2.9000 xml2_1.0.0       RSelenium_1.6.2 

loaded via a namespace (and not attached):
 [1] httr_1.2.1     magrittr_1.5   R6_2.2.0       tools_3.3.2    curl_2.3       Rcpp_0.12.8   
 [7] jsonlite_1.2   caTools_1.17.1 openssl_0.9.6  bitops_1.0-6   XML_3.98-1.4  

My work flow is the following:

  1. PhantomJS: install in terminal using node npm (install node npm with brew: brew install node)

    npm install -g phantomjs
    phantomjs --version #To check if it installed
        2.1.1  #It did
    

    Onto my R session:

    library(RSelenium) 
    ptm <- phantom() #also tried running checkForServer() and startServer() first but both were deprecated with no substitute stated...
    

[ERROR - 2017-01-06T01:55:35.240Z] GhostDriver - main.fail - {"line":85,"sourceURL":"phantomjs://code/main.js","stack":"global code@phantomjs://code/main.js:85:56"}

phantomjs://platform/console++.js:263 in error

    rd <- remoteDriver(browserName = 'phantomjs')
    rd$open()

[1] "Connecting to remote server" Error: Summary: UnknownError
Detail: An unknown server-side error occurred while processing the command. class: java.util.concurrent.TimeoutException Further Details: run errorDetails method

  1. Chromedriver: downloaded from https://chromedriver.storage.googleapis.com/index.html?path=2.27/ and binary file placed in /usr/local/bin

    rd <-remoteDriver(browserName = 'chrome')
    rd$open() #At this point, Google Chrome opens up for 1 second and then closes and an error pops up
    

Selenium message:session not created exception from unknown error: Runtime.evaluate missing 'wasThrown' (Session info: chrome=55.0.2883.95) (Driver info: chromedriver=2.23.409710 (0c4084804897ac45b5ff65a690ec6583b97225c0),platform=Mac OS X 10.12.2 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.09 seconds Build info: version: '3.0.0-beta2', revision: '2aa21c1', time: '2016-08-02 15:03:28 -0700' System info: host: 'Cyrus-M.local', ip: '10.0.1.3', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_101' Driver info: org.openqa.selenium.chrome.ChromeDriver

Error: Summary: SessionNotCreatedException Detail: A new session could not be created. class: org.openqa.selenium.SessionNotCreatedException Further Details: run errorDetails method

  1. Firefox: installed gecko driver in /usr/local/bin (without this the following code would produce an error indicating I needed the gecko driver installed)

    remDr <- remoteDriver$new()
    remDr$open() #a blank Firefox page opens up but then the following error is produced)
    

[1] "Connecting to remote server"

Selenium message:Unsupported Marionette protocol version 2, required 3 (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 1.06 seconds Build info: version: '3.0.0-beta2', revision: '2aa21c1', time: '2016-08-02 15:03:28 -0700' System info: host: 'Cyrus-M.local', ip: '10.0.1.3', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_101' Driver info: org.openqa.selenium.firefox.FirefoxDriver

Error: Summary: UnknownError Detail: An unknown server-side error occurred while processing the command. class: org.openqa.selenium.WebDriverException Further Details: run errorDetails method

    remDr$navigate("http://www.google.com")

Error in checkError(res) : Undefined error in httr call. httr output: length(url) == 1 is not TRUE

Any help is much appreciated.

UPDATE

After upgrading Firefox to the beta version (51.0b11), I can browse successfully but the problems persist using Chrome and PhantomJS.

remDr <- remoteDriver$new()
remDr$open()

[1] "Connecting to remote server"
$rotatable
[1] FALSE

$raisesAccessibilityExceptions
[1] FALSE

$appBuildId
[1] "20170103031119"

$version
[1] ""

$platform
[1] "MAC"

$proxy
named list()

$command_id
[1] 1

$nativeEvents
[1] TRUE

$specificationLevel
[1] 0

$acceptSslCerts
[1] FALSE

$processId
[1] 7529

$webdriver.remote.sessionid
[1] "64ac4d92-5761-4865-ba60-9cfaafe92a14"

$browserVersion
[1] "51.0"

$platformVersion
[1] "16.3.0"

$XULappId
[1] "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"

$browserName
[1] "firefox"

$takesScreenshot
[1] TRUE

$javascriptEnabled
[1] TRUE

$takesElementScreenshot
[1] TRUE

$platformName
[1] "darwin"

$cssSelectorsEnabled
[1] TRUE

$id
[1] "64ac4d92-5761-4865-ba60-9cfaafe92a14"

remDr$navigate("http://www.google.com") #Firefox opens up and browsing is accessible

来源:https://stackoverflow.com/questions/41497898/using-rselenium-on-mac-sierra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!