mercredi 17 avril 2019

How to make RSelenium avoid an "ok box" before a pdf visualiser when document is not available?

I am using RSelenium to download pdf documents from a database. Some of the documents are available, but, in some cases, the repository is not correct, and a box informing the problem appears (see http://imagem.camara.gov.br/dc_20b.asp?selCodColecaoCsv=D&Datain=16/5/1913#/). It is in Portuguese, and the message says that an error occurred).

I have already tried to identify some characteristics of the box via remDr$findElements(using="class name","modal-content"), but, when the the file link is not broken, the code takes too long to respond and returns the following error message:

Error:   Summary: NoSuchElement
         Detail: An element could not be located on the page using the given search parameters.
         class: org.openqa.selenium.NoSuchElementException
         Further Details: run errorDetails method

My code probably is not much efficient, but, according to other answers, would be effective. The source of problems lies in the third line.

for(link in links){
  remDr$navigate(link)
    if(length(remDr$findElements(using="class name","modal-content"))==0){ 
      botao<-remDr$findElement(using="id","download")
      botao$clickElement()
     }
  }

Probably, there are also other ways to download the pdf using Firefox, but this is enough for what I need.




Aucun commentaire:

Enregistrer un commentaire