【发布时间】:2015-03-27 18:37:38
【问题描述】:
我可以成功登录网站,然后填写表格并获得结果。 现在我试图为任何使用我的应用程序的人做这件事。问题是我必须填写的表单的字段名称会随着用户数量而变化。
像这样:
casper.thenOpen('http://www.foo.com/index.html', function() {
this.fill('form[action="/cgi-bin/login.cgi"]', { login: user,password:pass }, true);
this.click('input[type="submit"][name="enter"]');
this.wait(5000,function(){
this.capture('eff_ss2.png');
});
});
直到这里一切都很好(我阅读了登录信息并通过casper.cli.raw.get();
然后我这样做:
this.fill('form[action="../foo.cgi"]', {
'from_city': ori,
'to_city': dest,
'plan_03231': 'whatev',
'aspp_03231': 'whatev'
}, true);
03231 会根据登录的用户而变化。我怎样才能动态地做到这一点?我已经尝试过:
var plan = 'plan_0'+user;
var obj{}
obj[plan] = 'whatev'
this.fill('form[action="../foo.cgi"]', {
'from_city': ori,
'to_city': dest,
obj,
'aspp_03231': 'whatev'
}, true);
但不工作。有人可以帮帮我吗?
【问题讨论】:
标签: javascript global-variables casperjs