CasperJS constantly checks if a selector exists

I am doing some scraping with casperjs and while the script is running, I also have to check if the technical difficulty page appears. This page can appear at any time while browsing the site, so I can't just put one test at the beginning, it has to be tested constantly. Is there a way in CasperJS / PhantomJS, like a listener or something?

The following should start:

casper.checkIfThereIsTechError = function() {
    return casper.evaluate(function() {
        return __utils__.exists({
            type: 'xpath',
            path: '//a[@href="......'
        });
    });
};

      

+3


source to share


1 answer


in casper js, everything is presented as a step. Inside each step, call your function first to check for errors.



  casper.then(
  function(){
   isErrorexists = casper.checkIfThereIsTechError()
   if (!isErrorexists){
    do what you want to do here...
       }
     }
  )

      

0


source