waitForSelectors不选择DOM中的元素

时间:2016-07-16 16:19:45

标签: javascript jquery phantomjs casperjs

我正在尝试使用以下CasperJS脚本登录我的Verizon帐户:

var casper = require('casper').create({
    clientScripts:["/Developer/CasperJS/node_modules/jquery/dist/jquery.min.js"],
    verbose: true,
    logLevel: "debug",
    pageSettings: {
        loadImages: false
    }
});

//get pwd and id from command line
var utils = require('utils');
var id = casper.cli.raw.get('id');
var pwd = casper.cli.raw.get('pwd');
var challenge = casper.cli.raw.get('challenge');


casper.start("https://login.verizonwireless.com/amserver/UI/Login", function(){
    console.log("Verizon site opened");
});

casper.then(function(){
    console.log("Login");
    casper.waitForSelector("form#login-form", function (){
        this.fillSelectors('form#login-form', {
            'input[id=IDToken1]': id
        }, true);
    });
});

casper.then(function(){
    console.log("Challenge");
    casper.waitForSelector("#challengequestion", function(){
        this.fillSelectors('form#challengequestion', {
            'input[id=IDToken1]': challenge
        }, false);
    });
});


casper.then(function(){
    console.log("taking screenshot");
    this.capture('login.png');
})

casper.run();

当我运行该脚本时,完成Challenge部分的所有步骤。我确认我使用的是正确的选择器。以下是Verizon页面的相关表格:

<form id="challengequestion" name="challengequestion" method="post" action="https://login.verizonwireless.com:443/amserver/UI/Login">
<fieldset>
    <input type="hidden" name="goto" value="">
    <input type="hidden" name="userID" value="5555555555">

    <input type="hidden" name="displayLoginStart" value="true">
    <input id="IDToken1" type="password" value="" autocomplete="off" name="IDToken1" tabindex="1" class="same-line">

    <p><a class="o-link-strong" href="https://login.verizonwireless.com/accessmanager/public/c/fp/start?fa=true" onclick="forgotMyAnswerClicked();" target="_top">Forgot your answer?</a></p>


    <div id="remember-me-checkbox">
        <input type="checkbox" name="rememberComputer" id="rememberComputer" tabindex="2" value="Y" checked="checked"><label for="rememberComputer">Register this device</label>
        <span class="o-icon-question" data-toggle="tooltip" title="" tabindex="0" data-placement="bottom" data-original-title="&quot;Register this device&quot; stores information on your device so we know you are a My Verizon registered customer. You should not use this feature on public devices (such as those in a public library).">&nbsp;</span>
    </div>
    <input type="hidden" name="rememberComputerCheckBoxExists" value="Y">



    <button id="continueButton" class="o-red-button same-line" type="submit" onclick="continueClicked();">Continue</button>


    <input type="hidden" name="mode" value="o">

</fieldset>
</form>

最后输出:

Challenge
[info] [phantom] Step anonymous 6/7: done in 2791ms.
[info] [phantom] Step _step 7/8 https://login.verizonwireless.com/amserver/UI/Login (HTTP 200)
[info] [phantom] Step _step 7/8: done in 2812ms.
[warning] [phantom] Casper.waitFor() timeout
[error] [phantom] Wait timeout of 5000ms expired, exiting.
Wait timeout of 5000ms expired, exiting.
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"

我做错了什么?任何帮助将不胜感激!

0 个答案:

没有答案