【问题标题】:Try and catch is not working尝试和捕捉不起作用
【发布时间】:2016-02-04 15:58:00
【问题描述】:

我使用以下代码:

require(RSelenium)
startServer()
remDr <- remoteDriver()
remDr$open()
for (i in 1:length(url_list)) {
  url <- url_list[i]
  x <- remDr$navigate(url)
  if (class(x)=="try-error" ) {
     cat("something happened at ",something,"\n")
     next
  } else {
  remDr$refresh()
  Sys.sleep(2) #allow browser to catch up
    result <-  remDr$executeScript('return window.location;')
  #other code
}
}

我尝试使用一种方法尝试捕获错误,即使出现错误,我的代码也会继续运行。但是我的命令停止执行并出错:

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

代码有问题吗?

即使加载了某些 URL,也会发生此错误。

【问题讨论】:

    标签: r exception try-catch


    【解决方案1】:

    试试这个:

    x <- tryCatch({
            remDr$navigate(url)
         }, error = function(e) {
              print(paste0("error: ", e, " at: ", i)
              return(NULL)
         })
    
    if (!is.null(x)) {
       remDr$refresh()
        Sys.sleep(2) #allow browser to catch up
        result <-  remDr$executeScript('return window.location;')
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 2011-02-12
      • 1970-01-01
      相关资源
      最近更新 更多