2015-11-04 74 views
0

我使用下面的代碼:嘗試和捕捉不工作

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已加載,也會發生此錯誤。

回答

0

試試這個:

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;') 
}