【问题标题】:CasperJS fill form without form idCasperJS填写没有表单ID的表单
【发布时间】:2017-07-21 12:39:04
【问题描述】:

所以我遇到了问题,我无法填写此表格,因为没有 ID 和 class=login 他找不到它。 我试过sendkeysthis.fillSelectorsdocument.querySelectorthis.fill....

<div id="login_panel">
                <form action="?s=user" method="POST" class="login">
                    <center><input style="margin-top:20px; margin-left:16px;" type="text" class="input" name="userid" onfocus="if(this.value=='User')this.value=''" onblur="if(this.value=='')this.value='User'" value="User">
                    <input style="margin-top:-2px; margin-left:16px;" type="password" class="input" name="userpass" onfocus="if(this.value=='Password')this.value=''" onblur="if(this.value=='')this.value='Password'" value="Password">
                    <a href="index.php?s=pass_lost">* Passwort vergessen?</a>
                    <input style="margin-top:5px; margin-left:16px;" type="submit" class="bt_enter" value="LOGIN" name="submit"></center>\
                </form>
            </div>

【问题讨论】:

  • 你能贴出你试过的代码吗?在.fill.fillSelectors 上使用类选择器而不是ID 选择器应该可以正常工作。您是否在等待表单加载后再尝试填写?
  • 我等到加载一些 .jpg ..(它工作了一次)。

标签: javascript phantomjs casperjs


【解决方案1】:

我等到加载一些 .jpg ..(它工作了一次)。

casper.then(function() {
 this.evaluate(function(username, password) {
        document.querySelector('input[node-type="userid"]').value = username;
        document.querySelector('input[node-type="userpass"]').value = password;
        document.querySelector('.W_btn_g:eq(1)').click();
        this.click('input[value="LOGIN"]'); 
    }, 'Dantes999', '123456789');
});
casper.then(function() {
    this.sendKeys('input[name=userid]', 'Dantes999');
    this.sendKeys('input[name=userpass]', '123456789');
    this.click('input[value="LOGIN"]'); 
});
casper.then(function() {
this.fillSelectors('form#login_panel', {
    'input[name=userid]': 'Dantes999',
    'input[name=userpass]': '123456789'
}, true);
});
casper.then(function() {
    this.fill('form[class="login"]', {
          'userid': 'Dantes999',
          'userpass': '123456789'
        }, true);
});

【讨论】:

    猜你喜欢
    • 2013-10-27
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多