简体   繁体   中英

PhantomJS: Wait for page execution

I need phantomJS to wait for sometime after clicking the button inorder to get result. This result is stored in a div tag. I want to do something with this result.

I understood that javascript does not have sleep() like other languages

I tried using,

setTimeout(function () {
           var b = $("#idresult").text();
                        console.log("In windows timeout"+b);

        }, 10000); 

And

function sleep(delay) {
                var start = new Date().getTime();
                while (new Date().getTime() < start + delay);
            }

Calling of sleep

$("#idrun").click();
 sleep(100000);

But neither of them worked. These two functions are placed in page.evaluate(). Any other ways to do this.

I really appreciate your help!

Just wait inside of PhantomJS script, then evaluate:

setTimeout(function () {
    page.evaluate(function(){
        var b = $("#idresult").text();
        console.log("In windows timeout"+b);
    });
}, 10000); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM