我有html代码,如下所示选择名称为:
(我需要填写更多选择包含在mainForm中):
<select id="mainForm:projectSelectOneMenu" name="mainForm:projectSelectOneMenu" class="selectOne" size="1" onchange="A4J.AJAX.Submit('mainForm',event,{'similarityGroupingId':'mainForm:j_id416','parameters':{'mainForm:j_id416':'mainForm:j_id416'} ,'containerId':'mainForm:trainPeriodCriteriaRegion'} )">
<option value="">--- All ---</option>
我正在使用此代码:
this.fillSelectors('form#mainForm', {
'select[name="mainForm:projectSelectOneMenu"]' : "3"
}, false);
this.wait(6000,function(){
this.echo("i saw my new value");
});
我有这个错误:
CasperError:填写表单时遇到错误:没有字段匹配css选择器&#34;选择[name =&#34; mainForm:projectSelectOneMenu&#34;]&#34;形式。
我还使用其他方式来填充选区,但似乎我无法使用我的脚本来识别选择名称。
好的,现在它可以工作,我填写了我需要的所有选择。现在最后一步是单击按钮mainForm:updateTrainPeriodCriteriaButton:
</table>
<br><input id="mainForm:updateTrainPeriodCriteriaButton"
name="mainForm:updateTrainPeriodCriteriaButton" value="Apply" onclick="A4J.AJAX.Submit('mainForm',event,{'similarityGroupingId':'mainForm:j_id459','parameters': {'mainForm:j_id459':'mainForm:j_id459'} ,'containerId':'mainForm:trainPeriodCriteriaRegion'} )" type="submit">
<hr>
使用您的代码:
console.log("id = mainForm:updateTrainPeriodCriteriaButton ? -> "+this.getElementAttribute('input[name="mainForm:updateTrainPeriodCriteriaButton"]','id'));
输出正确: id = mainForm:updateTrainPeriodCriteriaButton? - &GT;的MainForm:updateTrainPeriodCriteriaButton
但我无法点击它:
casper.then(function(){
this.waitUntilVisible('#mainForm', function(){
this.fill('form#mainForm', {
'mainForm:criteriaStartCalendarInputDate': "2014/03/27 05:00",
'mainForm:criteriaEndCalendarInputDate': "2014/03/27 07:59",
}, false);
});
//Click
this.thenClick('#mainForm:updateTrainPeriodCriteriaButton');
this.then(function(){
this.wait(10000, function(){
this.capture('After_click.png');
});
});
});
错误:
CasperError:无法在不存在的选择器上调度mousedown事件:#mainForm:updateTrainPeriodCriteriaButton
答案 0 :(得分:2)
编辑:我尝试过选择[name =&#34; mainForm:projectSelectOneMenu&#34;]&#39; :&#34; 3&#34;它有效...
尝试使用:
//Emitted when a screenshot image has been captured.
casper.on('capture.saved', function(targetFile) {
this.echo('screen properly done at ' + targetFile);
});
this.fillSelectors('form#mainForm', {
'select[name*="mainForm"]' : "3"
}, false);
this.wait(2000,function(){
this.echo("i saw my new value");
this.capture('imgFormCasper.jpg', undefined, {
format: 'jpg',
quality: 75
});
});
或者那个:
this.fillSelectors('form#mainForm', {
'select[name*="projectSelectOneMenu"]' : "3"
}, false);
this.wait(2000,function(){
this.echo("i saw my new value");
this.capture('imgFormCasper.jpg', undefined, {
format: 'jpg',
quality: 75
});
});
所以试试这个指令:
console.log("id = mainForm:projectSelectOneMenu ? -> "+this.getElementAttribute('select[name="mainForm:projectSelectOneMenu"]','id'));
你应该: 如果您还没有IDE,请在此处测试您的代码,以确保您没有语法错误:http://esprima.org/demo/validate.html