javascript - CasperJS screenshot is only a small part of page - Stack Overflow

The CasperJS documentation for captureSelector() does not say anything about how to set the size of the

The CasperJS documentation for captureSelector() does not say anything about how to set the size of the screenshot. The default (at least on my system using webkit, Windows 8) seems to be to take a tiny screenshot of the top left portion of the page.

Am I looking in the wrong place?

I found viewportSize. I assume this is what I need, but does anyone have code that can set this to a sensible default (like 100%)?

FYI this.viewport('100%', '100%'); just hangs, so I assume it doesn't take %.

Do I have to inject code that will return the window width and height into the page and pass that back to extract it or is there an easier way?

The CasperJS documentation for captureSelector() does not say anything about how to set the size of the screenshot. The default (at least on my system using webkit, Windows 8) seems to be to take a tiny screenshot of the top left portion of the page.

Am I looking in the wrong place?

I found viewportSize. I assume this is what I need, but does anyone have code that can set this to a sensible default (like 100%)?

FYI this.viewport('100%', '100%'); just hangs, so I assume it doesn't take %.

Do I have to inject code that will return the window width and height into the page and pass that back to extract it or is there an easier way?

Share Improve this question edited Mar 19, 2015 at 23:13 Artjom B. 62k26 gold badges135 silver badges230 bronze badges asked Mar 19, 2015 at 22:52 pilavdzicepilavdzice 9589 silver badges27 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

casper.captureSelector() should take the screenshot of the element that you select. If you want to take a screenshot of the whole page you need to use casper.capture().

Note that PhantomJS has a default viewportSize of 400x300. Some pages don't resize correctly, so a part of the page is not visible. You will need to set this to something desktop-like:

var casper = require('casper').create({
    viewportSize: {width: 1280, height: 800}
});

There is no way to make it 100%. What you could do is read out the width of the body of the page and set the viewport accordingly through casper.viewport().

var width = 1280;
casper.start(url, function(){
    width = this.evaluate(function(){
        return document.body.clientWidth;
    });
}).viewport(width, 800).then(function(){
    this.capture("screenshot.png");
}).run();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744760461a4592144.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信