-1

I've got phantomjs and casperjs working on a webserver. I've got a webpage up with a form on it and two fields in the form (name and email address).

I need to input both 'name' and 'email' as variables into my casper script. From reading

Pass parameter from php to casperjs/phantomjs

and

http://phantomjs.org/api/system/property/platform.html

I understand you need to put var system and var args but it all seems like double dutch to me.

Php code

$name = $_POST['user_input'];
$email = $_POST['user_input'];
putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
exec('/usr/local/bin/casperjs hello.js $name $email 2>&1',$output);

print_r($output);

casperjs code

var system = require('system');
var args = system.args;
var name = args
var email = args

var casper = require('casper').create({
  verbose: true,
});
casper.start('website url');



casper.then(function () {
    casper.wait(5000); 
        this.echo("wait for 5 seconds.");

});
casper.then(function () {

    this.sendKeys('#firstname', name);
    this.sendKeys('#thereemail', email);
    this.click('.button');

From the looks of it I need to get both into one argument and then split them but how would I go about doing that?

Edit: The method posted would not work

2

1 Answer 1

1
var casper = require("casper").create({
  verbose: true,
});
var name = casper.cli.args[0];
var email = casper.cli.args[1];

See also: very close answer to your question; official CasprJS docs on working with CLI

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.