Is it possible to dump the console.log result ?

306 views
Skip to first unread message

Stéphane Klein

unread,
Dec 18, 2012, 9:57:56 AM12/18/12
to casp...@googlegroups.com
Hi,

is it possible to dump the console.log result ?

Example :

casper.then(function () {
    this.evaluate(function() {
        console.log($('.foobar').css());
    });
});

In my console, I've :

[info] [remote] [object Object]

How can display the dump of [object Object] ?

Best regards,
Stephane

Leandro Boscariol

unread,
Dec 18, 2012, 10:26:26 AM12/18/12
to casp...@googlegroups.com
Try using JSON.stringify() on that object:

casper.then(function () {
    this.evaluate(function() {
        console.log(JSON.stringify($('.foobar').css()));
    });
});

Cheers,
--
Leandro Boscariol






--
CasperJS homepage & documentation: http://casperjs.org/
CasperJS @github: https://github.com/n1k0/casperjs
 
You received this message because you are subscribed to the Google Groups "casperjs" group.
Visit this group at http://groups.google.com/group/casperjs?hl=en.
 
 

Nicolas Perriault

unread,
Dec 18, 2012, 10:31:04 AM12/18/12
to casp...@googlegroups.com
On Tue, Dec 18, 2012 at 3:57 PM, Stéphane Klein <step...@harobed.org> wrote:

> casper.then(function () {
> this.evaluate(function() {
> console.log($('.foobar').css());
> });
> });

If you want to print JSON serialized stuff right from within
evaluate(), you can do:

this.evaluate(function() {
__utils__.echo(JSON.stringify($('.foobar').css(), null, 4));
});

But you can also do it from the casper env as well:

casper.then(function() {
require('utils').dump(this.evaluate(function() {
return $('.foobar').css();
}));
});

This is untested though, as jQuery may return complex, unserializable objects.

++



--
Nicolas Perriault
https://nicolas.perriault.net/
Phone: +33 (0) 660 92 08 67
Reply all
Reply to author
Forward
0 new messages