Lance Perry
Lance Perry

Reputation: 1306

CasperJS captureSelector does not capture selector, captures whole page

I have a dashboard in Google Analytics. I want to only capture a certain part of the dashboard using CasperJS.

No matter what I've tried it captures the entire page.

What I'm I doing wrong here?

This is the HTML hierarchy that I find when I inspect the Google Analytics dashboard:

<div id="ID-view">
    <div class="_GAeH" id="ID-dashboard">
       <div id="ID-layout">
          <div class="_GARW ">
             <div class="_GAoA">
                <!-- more <div>s with the content -->
             </div>
          </div>
       </div>
    </div>
</div>

CasperJS code snippet:

var casper = require('casper').create();

casper.start('https://www.google.com/analytics/web/the/rest/of/the/url/', function() {
    this.fill('form#gaia_loginform', { 'Email': 'user', 'Passwd':'pass' }, true);
});

casper.waitForSelector('.ID-row-4-0-0', function() {
    casper.page.paperSize = {
        height: '11in',
        width: '8.5in',
        orientation:'portrait',
        border: '0.4in'
    };

// NONE of these work the way I think they should
// this.captureSelector('ga.pdf','#ID-view');
// this.captureSelector('ga.pdf','#ID-dashboard');
// this.captureSelector('ga.pdf','#ID-layout');
this.captureSelector('ga.pdf','._GAoA');
// this.captureSelector('ga.pdf','._GARW'); // <-- this one fails, capture height is messed up
},
function() {
    this.echo("Timeout reached");
});

casper.run();

Upvotes: 1

Views: 1319

Answers (1)

Rodrigo Andrade
Rodrigo Andrade

Reputation: 449

Try this:

this.captureSelector('ga.pdf','div._GAoA', {quality: 100});

If you cant take the screenshot of the element _GAoA please share the output of your casperjs scrpit.

Good luck.

Upvotes: 2

Related Questions