使用 Rselenium,无法再导航

with Rselenium, can't navigate anymore

几天前我问答了 得到了 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)
    }
}
在我的例子中,

ipAddrchar(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

您需要打开与 Selenium 服务器的连接:

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()

对于 RSelenium 用户 运行 没有 Docker 并且遇到错误

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

使用,

remDr <- driver[["client"]]
remDr$navigate("http://www.google.com")

启动浏览器后

remDr <- remoteDriver(browserName = "chrome")