0

i am stuck with the following scenario. the scenario is, in my web page i have some files and i need to download that one. When i click on download button it throws download window. And how to automate this thing. I am using CasperJS and SlimerJS....below is the html code

<ul class="dropdown-menu">
<li>
<li>
<li>
<li>
<a id="export_notebook_gist" href="#">Export Notebook to File</a>
</li>
<li>
<li>
<li>
<li>
</ul>
</ul>

1 Answers1

0

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..

Jasnan
  • 4,054
  • 2
  • 18
  • 23