You can use casper's download function to download a resource from a target page. All you have to do is to find the resource url that is linked to the download button and pass it to the casper's download function.
here is an example
//Download a PDF report
casper.then(function() {
var fs = require('fs');
var dataurl = this.findElUrl('#_2a7a2a0a2a1a0a'); // This is a jQuery function that finds the PDF file's url.
var file = new Date().getTime() + '.pdf';
var fileloc = apppath + 'reports/' + file;
self.download(dataurl, fileloc); // will download PDF to the specified directory
});
And the function to find the PDF url is
casper.findElUrl = function(selector){
var test = this.evaluate(function(selector) {
return $(selector).data('url');
},selector);
return test;
}
BTW, you have to inject jQuery to the target page using casper's client script as follows.
var casper = require('casper').create({
pageSettings: {
webSecurityEnabled: false,
loadImages: false,
loadPlugins: false
},
clientScripts: ["./jquery.min.js"]
});
hopes this helps..