【问题标题】:with Rselenium, can't navigate anymore使用 Rselenium,无法再导航
【发布时间】:2018-01-13 22:57:23
【问题描述】:

几天前我问并回答了this question,并让 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

【问题讨论】:

    标签: r selenium rselenium httpverbs


    【解决方案1】:

    您需要打开与 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()
    

    【讨论】:

      【解决方案2】:

      对于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")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多