嗨,我想知道如何使用 casperjs 获取输入值
这是我的html元素
<input type="hidden" name="key" value="newkey">
这是我试过的:
view = 'users/registered';
casper.test.begin("Activating account", 5, function register(test){
casper.start(webroot + view, function(){
}).then(function(){
this.echo("Retrieving data from hidden input key", "COMMENT");
activationKey = this.evaluate(function() {
return __utils__.getFieldValue('key');
});
}).then(function(){
this.echo("Activating account with the key \"" + activationKey + "\"", "COMMENT");
window.location = webroot + activationKey;
});
casper.run(function() {
this.echo('Account activated successfully', 'SUCCESS').exit();
test.done();
});
});
casper.viewport(page.width, page.height);
在这种情况下返回null
我也试过:
activationKey = __utils__.getFieldValue('key');
但是返回这个错误:
FAIL ReferenceError: Can't find variable: __utils__
最佳答案
尝试使用这个:
this.getElementAttribute('input[type="hidden"][name="key"]', 'value');
关于javascript - 在casperjs中获取输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23199489/