[英]Trying to fill table element by id with casperjs
casper.thenEvaluate(function(text){
document.querySelector("#inputValue").value=text
})
casper.thenEvaluate 似乎不接受該參數,它在網頁中填寫未定義。
根據文檔,您應該在“開始”之后使用“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();
來源:
http://docs.casperjs.org/en/latest/modules/casper.html#thenevaluate
由於評估在瀏覽器上下文(而不是 Casper 上下文)中運行,因此您必須在回調函數定義之后顯式提供變量。 請檢查文檔中的示例
casper.evaluate(function(username, password) {
document.querySelector('#username').value = username;
document.querySelector('#password').value = password;
document.querySelector('#submit').click();
}, 'sheldon.cooper', 'b4z1ng4');
請注意,回調中的用戶名參數對應於sheldon.cooper
,密碼參數對應於b4z1ng4
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.