Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7972725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:56:23+00:00 2026-06-04T07:56:23+00:00

Here is my PhantomJS test project which I run in cmd.exe by typing (for

  • 0

Here is my PhantomJS test project which I run in cmd.exe by typing (for example):

>phantomjs.exe abacus.js 1111 222
name: 1111
pass: 222
load started
load finished
jQuery loaded
console> name:
console> pass: undefined
step 0
step 1
done

Abacus.js:

var name, pass;
if (phantom.args.length !== 2) {
    console.log('not enough arguments!');
    phantom.exit();
} else {
    name = phantom.args[0];
    pass = phantom.args[1];
}
console.log("name: " + name);  //output: "name: MyUsername"
console.log("pass: " + pass);  //output: "pass: MyPassword"
var stepIndex = 0;
var page = new WebPage();
var loadInProgress = true;
var jQueryLoad = false;
page.onConsoleMessage = function (msg, line, source) {
    console.log('console> ' + msg);
};
page.onAlert = function (msg) {
    console.log('alert> ' + msg);
};
page.onLoadStarted = function () {
    loadInProgress = true;
    console.log("load started");
};
page.onLoadFinished = function () {
    loadInProgress = false;
    console.log("load finished");
    jQueryLoad = page.injectJs("jquery-1.7.1.min.js");
    if (jQueryLoad)
        console.log('jQuery loaded');
};
var interval = setInterval(function () {
    if (jQueryLoad && !loadInProgress && typeof steps[stepIndex] == "function") {
        steps[stepIndex]();
        page.render("step " + stepIndex + ".png");
        console.log("step " + stepIndex++);
    } 
    if (typeof steps[stepIndex] != "function") {
        console.log("done");
        phantom.exit(); 
    } 
}, 1000);
var steps = [
function () {
    page.evaluate(function () {
        console.log("name: " + this.name);  //output: "console> name:"
        console.log("pass: " + this.pass);  //output: "console> pass: undefined"
        var arr = document.frmMain;
        if (arr !== null) {
            arr.elements["username"].value = "MyUsername";  //Only fils in form if it's a string literal
            arr.elements["password"].value = "MyPassword";
        } else {
            console.log("Could not find frmMain");
        }
    });
}, function () {
    page.evaluate(function () {
        document.frmMain.submit();
    });
} ];
page.open("http://www.abacusdatagraphics.com/");
page.viewportSize = { width: 1280, height: 1024 };

Any help would be appreciated as to why phantom.args & name/pass suddenly lose their values.

I am running cmd.exe in C# since the name and password change every now and then and are kept in a database. This is simply a small test program to see if it can be done.

(Also, thanks to Stack Overflow for giving me most of this code in the first place)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:56:25+00:00Added an answer on June 4, 2026 at 7:56 am

    @jlafay

    The solution I used from this is as such:

    PhantomJS wasn’t able to fill in the forms with variables because page.evaluate can’t handle parameters so when filling out the form, the variables (and the forms) are null.

    So instead I treated function() as a string and passed the variables like this:

    page.evaluate('function () {' +
        'var theName = ' + name + ';' +
        'var thePass = ' + pass + ';' +
        'console.log(\"name: \" + this.name);' +  //output: "console> name:"
        'console.log(\"pass: \" + this.pass);' +  //output: "console> pass: undefined"
        'var arr = document.frmMain;' +
        'if (arr !== null) {' +
        '    arr.elements["username"].value = theName;' +
        '    arr.elements["password"].value = thePass;' +
        '} else {' +
        '    console.log("Could not find frmMain");' +
        '}' +
    '}');
    

    Or something like that, I don’t have the code anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to run my jamsine specs from command line using PhantomJs.exe. Here is
Here is a complete example. I want to forbid using A::set from objects casted
Here is an example: I write html code inside of textarea, then I swap
here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
I have a PhantomJS/CasperJS script which I'm running from within a node.js script using
Here an example of my checkbox list http://jsfiddle.net/YnM2f/ Let's say I check on G
Here a simple question : What do you think of code which use try
I have an Eclipse (java) project which stops at non-existent breakpoints. There was a
Here's an example list: <ul> <li><a href=#>Link 1</a></li> <li><a href=#>Link 2</a></li> <li><a href=#>Link 3</a></li>
here's my code private void make_Book(int x, int y, string name) { #region Creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.