Currently, I am using PhantomJS to capture a screenshot of the dashboard and save it as a PNG file. Everything works perfectly fine until I try to include additional arguments (line
, dFrom
, dTo
) and use them within the page.evaluateJavaScript()
function. Unfortunately, it doesn't seem to work as expected. Is there a method to utilize PhantomJS variables within the JavaScript function?
var page = require('webpage').create(),
system = require('system'),
address, output, size, line, dFrom, dTo;
address = system.args[1];
output = system.args[2];
line = "All";
dFrom = null;
dTo = null;
if (system.args.length > 2)
{
line = system.args[3];
dFrom = system.args[4];
dTo = system.args[5];
}
page.viewportSize = { width: 1200, height: 1800 };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit();
} else {
page.evaluate(function () {
var body = document.body;
body.style.backgroundColor = '#fff';
body.querySelector('div#nav-section').style.display = 'none';
body.querySelector('div#to-hide-btns').style.display = 'none';
body.querySelector('div#main-section').style.overflow = 'hidden';
});
page.evaluateJavaScript(function () {
selectedLine = line;
dateFrom = dFrom;
dateTo = dTo;
onCriteriaChange();
});
window.setTimeout(function () {
page.render(output, {format: 'png', quality: '100'});
console.log('done');
phantom.exit();
}, 2000);
}
})
In contrast, when I make this change, everything runs smoothly:
page.evaluateJavaScript(function () {
selectedLine = "S01";
dateFrom = "3/1/2015";
dateTo = "3/10/2015";
onCriteriaChange();
});