简体   繁体   English

尝试使用 casperjs 通过 id 填充表格元素

[英]Trying to fill table element by id with casperjs

casper.thenEvaluate(function(text){
    document.querySelector("#inputValue").value=text
})

casper.thenEvaluate seems to not accept the argument and it is filling undefined in the webpage. casper.thenEvaluate 似乎不接受该参数,它在网页中填写未定义。

According to the documentations you should use "thenEvaluate" after "start" like this:根据文档,您应该在“开始”之后使用“thenEvaluate”,如下所示:

// Querying for "Chuck Norris" on Google
casper.start('http://google.fr/').thenEvaluate(function(term) {
    document.querySelector('input[name="q"]').setAttribute('value', term);
    document.querySelector('form[name="f"]').submit();
}, 'Chuck Norris');

casper.run();

source:来源:

http://docs.casperjs.org/en/latest/modules/casper.html#thenevaluate

Since evaluate runs in browser context(instead of Casper one) you have to explicitly provide variables after the callback function definition.由于评估在浏览器上下文(而不是 Casper 上下文)中运行,因此您必须在回调函数定义之后显式提供变量。 Please check example from the docs请检查文档中的示例

casper.evaluate(function(username, password) {
  document.querySelector('#username').value = username;
  document.querySelector('#password').value = password;
  document.querySelector('#submit').click();
}, 'sheldon.cooper', 'b4z1ng4');

Note that username param in callback corresponds to sheldon.cooper and password param corresponds to b4z1ng4 .请注意,回调中的用户名参数对应于sheldon.cooper ,密码参数对应于b4z1ng4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM