How can I make casperjs repeat a loop until a certain condition is met?

北城以北 提交于 2019-12-05 21:55:41

Pius had the right idea, I modified my code, the solution is below.

var urls = {
    login : 'http://www.website.com/login',
    details : 'http://www.website.com/details',
};

casper.start(urls.login, function() {

    //login stuff

});

//the function I'm trying to recursively loop before moving on to saving the capture image
function checkMore() {

    //check to see if the 'read more' button exists
    if (casper.exists('a.read-more')) {

        //click the button to load more items           
        casper.click('a.read-more');

        //wait for the items to load, then run the check again
        casper.wait(3000, checkMore);

    }

}

casper.thenOpen(urls.details, function() {

    //wait for the page along with ajax items to load shortly after
    this.wait(3000, checkMore);

});

casper.then(function() {

    //output the result
    this.capture('output.jpg');

});

casper.run();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!