1

I wrote a loop to go check a bunch of links and take screenshots. I often need to do these in the thousands. The loop I created works well for about 500 links and then my browser closes and I get the following error:

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

Is there a way to prevent this?

If not, how can I get R to run source code OpenBrowser.R if this happens?

Here is the script:

    for(i in 1:nrow(URL)){      
         remDr1$navigate(URL$Link[i])
         remDr1$setTimeout(type = "page load", milliseconds = 30000)
         remDr1$screenshot(file = URL$file[i])
         }
2
  • 1
    Take a look at tryCatch or purrr:safely Commented Jan 19, 2016 at 14:34
  • I haven't been able to understand how tryCatch works. Could you post an example of how I would use it in this code? Commented Jan 19, 2016 at 15:41

1 Answer 1

4

Few things can be tried like :-

Try this function :- (it will wait till full page load. If required you can remove page_load_time_out or make in Inf)

wait_till_page_load<-function(page_load_time_out=60){
  t0<-Sys.time()
  while(remDr$executeScript("return document.readyState;")[[1]]!="complete" & (Sys.time()-t0)<=page_load_time_out){
    Sys.sleep(0.5)
  }
  invisible(0)
}

Use it like :-

for(i in 1:nrow(URL)){      
         remDr1$navigate(URL$Link[i])
         #remDr1$setTimeout(type = "page load", milliseconds = 30000)
         wait_till_page_load(500000000) # use suitable number
         try(remDr1$screenshot(file = URL$file[i]))
}

Try will prevent from breaking the loop.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.