casperjs填充并单击不工作,因为我预期不能单击按钮 [英] casperjs fill and click not working as i expected cannot click button

查看:154
本文介绍了casperjs填充并单击不工作,因为我预期不能单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我会发布到下面的一组代码,我试图使用
并提交我的casperjs代码,我尝试使用html表单。当试图点击提交按钮时,问题出现了,我拍了一张截图并得到了html,但由于某种原因,html没有任何改变,屏幕截图显示了填充的字段,但表单尚未提交可以帮助我



heres html

 < form action =userlogin.html method =postname =regid =regonsubmit =document.getElementById('sbt')。disabled = true; return true;> 
< input type =hiddenname =submitvalue =1class =input>
< table cellpadding =0cellspacing =2>
< tbody>< tr>
< td valign =topwidth =123>< font face =Arial,Helvetica,sans-serifsize =2>< b> user< / b><< b> ; /字体>< / TD>
< td width =287> < font face =Arial,Helvetica,sans-serifsize =2>
< input type =textname =loginsize =20maxlength =20value =class =input>
< a href =/ remember.html>忘记了?< / a>< / font> < font face =Arial,Helvetica,sans-serifsize =2>
< / font>
< div class =error>< font face =Arial,Helvetica,sans-serifsize =2>< / font>< / div>
< / td>
< / tr>< tr>
< / tr>< tr>
< td valign =topwidth =123>< font face =Arial,Helvetica,sans-serifsize =2>< b>密码:< / b> ;< /字体>< / TD>
< td width =287> < font face =Arial,Helvetica,sans-serifsize =2>
< input type =passwordname =passwordsize =20class =keyboardInput inputid =keyboardInputInitiator0>< img src =/ img / keyboard.pngalt = 键盘界面class =keyboardInputInitiatortitle =显示图形键盘界面>
< / font>
< div class =error>< font face =Arial,Helvetica,sans-serifsize =2>< / font>< / div>
< / td>
< / tr>< tr>
< / tr>< tr>
< td valign =topwidth =123height =23>< font face =Arial,Helvetica,sans-serifsize =2>& nbsp;<< ; /字体>< / TD>
< td width =287height =23>< font face =Arial,Helvetica,sans-serifsize =2>& nbsp;< / font>
< / td>
< / tr>
< tr>
< td valign =topwidth =123>< font face =Arial,Helvetica,sans-serifsize =2>< b> Turing
number :其中/ b个;< /字体>< / TD>
< td width =287>< font face =Arial,Helvetica,sans-serifsize =2>< font face =Arial,Helvetica,sans-serifsize = 2 >
< input type =textname =turingsize =7maxlength =10class =input>
< / font>
< div class =error>< font face =Arial,Helvetica,sans-serifsize =2>< / font>< / div>< / font> < / TD>
< / tr>
< tr>
< td valign =topwidth =123>< font face =Arial,Helvetica,sans-serifsize =2>< img id =cpt_imgsrc = /user/turing/image.asp?1395177754\"><br>
< a style =text-decoration:none; cursor:pointer; HREF = JavaScript的:无效(0); onclick =document.images ['cpt_img']。src ='/ user / turing / image.asp?'+(new Date())。getTime(); return false;>
< table>< tbody>< tr>< td>< td valign ="中间>< < / TD>< / TR>< / tbody的>< /表>< / A>< /字体>< / TD>
< td width =287>
< / td>
< / tr>
< tr>
< td valign =topwidth =123height =40>& nbsp;< / td>
< td width =287height =40valign =bottom>
< input type =submitvalue =Authorizename =submitid =sbtclass =input submit>
< / td>
< / tr>
< / tbody>< / table>

和我的casperjs

  var casper = require('casper')。create({
waitTimeout:15000,
stepTimeout:15000,
详细:true,
viewportSize:{
width:1280,
height:960
},
pageSettings:{
userAgent:'Mozilla / 5.0(X11; Linux x86_64)AppleWebKit / 537.10 KHTML,像Gecko)Chrome / 23.0.1262.0 Safari / 537.10',
ignoreSslErrors:true
},
onWaitTimeout:function(){
// casper.capture( './out/wait-timeout:_'+ TimeTidy()+'.png');
//抛出新的错误信息;
},
onStepTimeout:function(){
// casper.capture('./out / step-timeout'+ TimeTidy()+'.png');
//抛出新的错误信息;
}
} );
var fs = require('fs');

var system = require('system');
pageSettings:{
webSecurityEnabled:false;


casper.start('https://example/login.html',function(){

//获取图片需要..
// var abc = this.getHTML('img#cpt_img',true).match(/ src =(。*?)/)[1];
// var url ='https: //示例'+ abc;
//this.download(url,abc.jpg);

//获取一些数据..
system.stdout.writeLine ('数据需要继续');
// var line = system.stdin.readLine();
//console.log(line);

//获取HTML源代码..
var el = this.getHTML();
fs.write('results.html',el,'w');

casper。 ('form [name =reg]',{
'login':'43532243',
'password':'dsfgsfdgh',
'turing':'3456'
},true);





casper.then(function(){
this.capture(filename .jpg);
var el2 = this.getHTML();
fs.write('results2.html',el2,'w');
});
});


casper.run();

为什么我的表单不能正确提交

解决方案

你已经在casper上下文中。尝试使用this.fill方法。只需用这个替换casper。请参阅下面的示例。



this.fill('form [name =reg]',{
'login':'43532243',
'密码':'dsfgsfdgh',
'turing':'3456'
},true);

okay so i will post to sets of code below one the html form i am trying to use and submit and my casperjs code i am trying. the problem comes when trying to click the submit button i take a screenshot and get the resulting html but for some reason the html has no change at all and the screenshot shows the fields filled in but the form has not been submitted can someone help me

heres the html

            <form action="userlogin.html" method="post" name="reg" id="reg" onsubmit="document.getElementById('sbt').disabled = true;return true;">
        <input type="hidden" name="submit" value="1" class="input">
          <table cellpadding="0" cellspacing="2">
            <tbody><tr>
              <td valign="top" width="123"><font face="Arial, Helvetica, sans-serif" size="2"><b>user</b></font></td>
              <td width="287"> <font face="Arial, Helvetica, sans-serif" size="2">
                <input type="text" name="login" size="20" maxlength="20" value="" class="input">
                <a href="/remember.html">forgot?</a></font> <font face="Arial, Helvetica, sans-serif" size="2">
                </font>
                <div class="error"><font face="Arial, Helvetica, sans-serif" size="2"></font></div>
              </td>
            </tr><tr>
            </tr><tr>
              <td valign="top" width="123"><font face="Arial, Helvetica, sans-serif" size="2"><b>Password:</b></font></td>
              <td width="287"> <font face="Arial, Helvetica, sans-serif" size="2">
                <input type="password" name="password" size="20" class="keyboardInput input" id="keyboardInputInitiator0"><img src="/img/keyboard.png" alt="Keyboard interface" class="keyboardInputInitiator" title="Display graphical keyboard interface">
                </font>
                <div class="error"><font face="Arial, Helvetica, sans-serif" size="2"></font></div>
              </td>
            </tr><tr>
            </tr><tr>
              <td valign="top" width="123" height="23"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;</font></td>
              <td width="287" height="23"><font face="Arial, Helvetica, sans-serif" size="2">&nbsp;</font>
              </td>
            </tr>
            <tr>
              <td valign="top" width="123"><font face="Arial, Helvetica, sans-serif" size="2"><b>Turing
                number:</b></font></td>
              <td width="287"><font face="Arial, Helvetica, sans-serif" size="2"><font face="Arial, Helvetica, sans-serif" size="2">
                <input type="text" name="turing" size="7" maxlength="10" class="input">
                </font>
                <div class="error"><font face="Arial, Helvetica, sans-serif" size="2"></font></div></font></td>
            </tr>
            <tr>
              <td valign="top" width="123"><font face="Arial, Helvetica, sans-serif" size="2"><img id="cpt_img" src="/user/turing/image.asp?1395177754"><br>
<a style="text-decoration:none;cursor:pointer;" href="javascript:void(0);" onclick="document.images['cpt_img'].src='/user/turing/image.asp?'+(new Date()).getTime();return false;">
<table><tbody><tr><td><img src="/img/reload.gif"></td><td valign="middle"></td></tr></tbody></table></a></font></td>
              <td width="287">
              </td>
            </tr>
            <tr>
              <td valign="top" width="123" height="40">&nbsp;</td>
              <td width="287" height="40" valign="bottom">
                <input type="submit" value="Authorize" name="submit" id="sbt" class="input submit">
              </td>
            </tr>
          </tbody></table>

and my casperjs

var casper = require('casper').create ({
waitTimeout: 15000,
stepTimeout: 15000,
verbose: true,
viewportSize: {
width: 1280,
height: 960
},
pageSettings: {
"userAgent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.10 (KHTML, like Gecko) Chrome/23.0.1262.0 Safari/537.10',
"ignoreSslErrors": true
},
onWaitTimeout: function() {
  // casper.capture('./out/wait-timeout:_' + TimeTidy() + '.png');
  // throw new Error stuff;
},
onStepTimeout: function() {
  // casper.capture('./out/step-timeout' + TimeTidy() + '.png');
  // throw new Error stuff;
 }
});
var fs = require('fs');

var system = require('system');
pageSettings: {
        webSecurityEnabled: false;
}

casper.start('https://example/login.html', function() {

// Get Image Needed..
//var abc = this.getHTML('img#cpt_img', true).match(/src="(.*?)"/)[1];
//var url = 'https://example' + abc;
//this.download(url, "abc.jpg");

// Get Some Data..
system.stdout.writeLine('Data Needed To Continue .');
//var line = system.stdin.readLine();
//console.log(line);

// Get HTML Source Code..
var el = this.getHTML();
fs.write('results.html', el, 'w');

casper.fill('form[name="reg"]', {
'login': '43532243',
'password': 'dsfgsfdgh',
'turing': '3456'
}, true);





casper.then(function() {
    this.capture("filename.jpg");
var el2 = this.getHTML();
fs.write('results2.html', el2, 'w');
});
});


casper.run();

why will my form not submit properly

解决方案

you are already in the casper context. try using this.fill method. simply replace casper with this. See example below.

this.fill('form[name="reg"]', { 'login': '43532243', 'password': 'dsfgsfdgh', 'turing': '3456' }, true);

这篇关于casperjs填充并单击不工作,因为我预期不能单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆