0

is there a way or work around to wait for something forever?

E.g.

I'll use fb as example because is the same thing on my site. Every time that there are new post on my facebook timeline, shows up a panel 'Click here to load the posts'.

Basically, what I need is trigger some action after the panel is visible(click on it). I know about waitUntilVisible, but it runs only one time and I'd like to run forever and capture many times.

Rodrigo Pereira
  • 1,834
  • 2
  • 17
  • 35

1 Answers1

0

Yes, you can start the wait function anew when the timeout is reached. This works because the onTimeout callback to casper.waitUntilVisible will be executed inside the step function of waitUntilVisible.

function continuous(){
    casper.waitUntilVisible("#someSelector", function then(){
        // do something on success
    }, continuous);
}

casper.start(url).then(continuous).then(function(){/* something further */}).run()

If you never want to terminate, just use an impossible selector for "#someSelector" or a custom waitFor:

casper.waitFor(function check(){ return false; }, function then(){
    // do something on success
}, continuous);
Artjom B.
  • 61,146
  • 24
  • 125
  • 222