I what to execute a phantomJS
script which download a webpage (args[1]) and save the result html into a file (args[2]) as follows:
var system = require('system');
var page = require('webpage').create();
var fs = require('fs');
// Set the url address and the path
var url = system.args[1];
var path = system.args[2];
page.open(url, function () {
fs.write(path, page.content, 'w');
phantom.exit();
});
I am using selenium/ghostdriver
to execute the script as follows:
DesiredCapabilities cap = new DesiredCapabilities();
cap.setJavascriptEnabled(true);
cap.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,".../phantomjs");
String [] phantomJsArgs = {url,path};
cap.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, phantomJsArgs);
PhantomJSDriver driver = new PhantomJSDriver(cap);
String content = new String(Files.readAllBytes(Paths.get(scriptPath)),Charset.forName("UTF-8"));
driver.executePhantomJS(content);
This code works except when I try to pass from selenium/ghostdriver
2 parameters call url
and path
to the phantomJS script as system.args[1]
and system.args[2]
. Any idea how to do this?