casper.captureSelector()should take a screenshot of the selected item. If you want to take a screenshot from the whole page, you need to use casper.capture().
Note that PhantomJS has a default viewportSize of 400x300. Some pages do not change correctly, so part of the page is not displayed. You will need to install this on your desktop:
var casper = require('casper').create({
viewportSize: {width: 1280, height: 800}
});
There is no way to do this 100%. What you can do is read the width of the page body and set the viewport accordingly 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();
source
share