2017-08-06 90 views
1

我問和答覆this question前幾天,並得到Rselenium運行良好。與Rselenium,無法導航

現在我不能導航了,我不認爲有任何改變,所以我感到困惑。

shell('docker run -d -p 4445:4444 selenium/standalone-chrome') 
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "chrome") 
remDr$navigate("http://www.google.com") # used to work 
# Error in checkError(res) : 
# Undefined error in httr call. httr output: length(url) == 1 is not TRUE 

我做了一些調試,並remDr$navigate呼叫被叫queryRD當問題發生的方法,請參見下面

debugging in: queryRD(qpath, "POST", qdata = list(url = url)) 
debug: { 
    "A method to communicate with the remote server implementing the \\n   JSON wire protocol." 
    getUC.params <- list(url = ipAddr, verb = method, body = qdata, 
     encode = "json") 
    res <- tryCatch({ 
     do.call(httr::VERB, getUC.params) # VERB doesn't like the url argument its getting 
    }, error = function(e) { 
     e 
    }) 
    if (inherits(res, "response")) { 
     resContent <- httr::content(res, simplifyVector = FALSE) 
     checkStatus(resContent) 
    } 
    else { 
     checkError(res) 
    } 
} 

ipAddr代碼是char(0),而不是在我的情況下,有效的URL。並且VERB不喜歡url它的結果。

如何恢復運行?

爲了得到調試在正確的地方:

shell('docker run -d -p 4445:4444 selenium/standalone-chrome') 
    remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "chrome") 
debugonce(remDr$navigate) 
remDr$navigate("http://www.google.com") 
debugonce(queryRD) 
c 

回答

1

您需要打開的硒服務器的連接:

library(RSelenium) 

remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, 
         browserName = "chrome") 
remDr$open() 
remDr$navigate("http://www.google.com") # used to work 
> remDr$getTitle() 
[[1]] 
[1] "Google" 
... 

remDr$close() 
+1

媽的,它必須有迷路的複製粘貼那是令人尷尬,, 非常感謝! –