私はphantom.jsで新しく、Webページをナビゲートしてリンクをクリックしようとしています(AJAX関数を呼び出し、ドキュメントHTML)にphantom.jsを追加します。ここでphantom.jsのリンクをクリックしてドキュメントを取得します。
は私のコードです:
window.setTimeout(function(){
phantom.exit();
}, 120000);
var page = require('webpage').create();
page.open("http://example.com", function(status) {
if (status !== 'success') {
console.log('{"error":"Unable to load the address for page"}');
phantom.exit();
}
var action = page.evaluate(function() {
document.getElementById("anID").click();
return "clicked";
});
var results = page.evaluate(function() {
return document.documentElement.innerHTML;
});
console.log(action);
window.setInterval(function() {
console.log(results);
phantom.exit();
}, 3000);
});
私の "アクション" 機能では、クリック()の呼び出しは、そのエラーが3回繰り返さ上げているように私は非常に混乱だ:また
TypeError: 'undefined' is not a function
phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():1
ph.js:121 nullTypeError: 'undefined' is not a function
phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():1
ph.js:121 nullTypeError: 'undefined' is not a function
phantomjs://webpage.evaluate():3 phantomjs://webpage.evaluate():1
ph.js:121 null
をクリックを送信したときにその行にコメントを付けると、アクション関数はエラーを発生させず、「クリックされた」コンソールログを返します。しかし3回...
私は間違っていますか?
ありがとうございます。
FYIあなたは、この行の後に2セミコロンを持っています。 'のdocument.getElementById(「ANID」)をクリックします();;'それはだ –
はいおかげでここに投稿する際の間違い、それでも問題があります。 – ronnieonrails