2016-11-24 90 views
2

我想抓取一个正在使用AngularJs的网站,页面上有四个单选按钮,其中有两个'ng-required = true'。所有四个按钮都被选中,但是当我点击提交按钮时,即使选择了按钮,它也会在单选按钮上出现错误。我截图,甚至在屏幕截图中显示选中的单选按钮。我试图覆盖验证,但没有任何工作。请帮助这里是HTML和代码使用Angular js抓取网站

的Html 这是公共服务的单选按钮

<input id="publicServiceTrue" type="radio" value="false" 
    name="ibrComposite.application.pslfIndicator" 
    ng-model="pslf" target="dependents_section_div" 
    ng-required="true"/> 

婚姻状况单选按钮

<input id="maritalStatusSingle" type="radio" value="SINGLE" 
name="ibrComposite.application.maritalStatus" 
ng-model="maritalStatus" ng-required="true" /> 

//卡斯帕代码

casper.then(function() { 
    this.evaluate(function() { 
     $('#applicationReason_NEW').prop("checked", true); 
    }); 

    this.evaluate(function() { 

     $('publicServiceTrue').prop("checked", true); // This radio button shows error even when it is selected 
    }); 

    this.evaluate(function(){ 

    $('#applicationNbChildren').val('0').change(); 
    $('#applicationNbDep').val('0').change(); 
    }); 
    casper.wait(800, function(){ 
     this.capture('IRS/Third_button.png') 
    }); 



    this.evaluate(function() { 
     $('#maritalStatusSingle').prop("checked", true); // This radio button shows error even when it is selected 


    }); 
    casper.wait(1000, function(){ 
     this.capture('IRS/Fourth_button.png') 
    }); 
    document.querySelectorAll("input[type='submit']")[0].click(); 
}); 
+4

报废一个网站?或刮。也不知道你实际上在问什么...... – Darren

+0

请增加清晰度。如果是这样的话,还要分享你的CasperJS代码。 –

+0

请[编辑问题](http://stackoverflow.com/posts/40793931/edit)包含HTML和JavaScript。作为评论,它们是不可读的。 – georgeawg

回答

1

this关键字.then m ethod不绑定到父母this。请使用胖箭头=>语法。

//casper.then(function() { 
//Use fat arrow syntax 
casper.then(() => { 
    this.evaluate(function() { 
     $('#applicationReason_NEW').prop("checked", true); 
    }); 

    this.evaluate(function() { 

     $('publicServiceTrue').prop("checked", true); // This radio button shows error even when it is selected 
    }); 

或明确绑定this关键字父:

var that = this; 
casper.then(function() { 
    //this.evaluate(function() { 
    that.evaluate(function() { 
     $('#applicationReason_NEW').prop("checked", true); 
    }); 

    //this.evaluate(function() { 
    that.evaluate(function() { 

     $('publicServiceTrue').prop("checked", true); // This radio button shows error even when it is selected 
    }); 

Promises/A+ Spec

3.3。也就是说,在严格模式thisundefined内(成功/拒绝处理程序);在马虎模式下,它将成为全球性的对象。

+0

感谢你的回应,但它并没有解决问题,因为我前面提到,该块中有其他控件被选中,但其中两个不是我在代码中明确注释的 –