我无法使用phantomjs自动化访问第二页 显示错误 类型错误: undefined不是一个对象(评估'r [20] .click') 未定义:7 :8
运行phantomjs代码时
console.log("got here");
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open(url, function(status) {
if ( status === "success" ) {
page.evaluate(function() {
document.getElementById("txtLoginName").value = "safvan";
document.getElementById("txtPassword").value = "safvan542";
document.forms["logInForm"].submit();
console.log("Login submitted!");
var r=document.getElementsByTagName("a");
r[20].click();
});
window.setTimeout(function () {
page.render('hrtesttime.pdf');
phantom.exit();
}, 15000);
}
});
答案 0 :(得分:0)
试试这段代码:
console.log("got here"); var page = require('webpage').create(); page.onConsoleMessage = function(msg) { console.log(msg); }; page.open(url, function(status) { if ( status === "success" ) { page.evaluate(function() { document.getElementById("txtLoginName").value = "safvan"; document.getElementById("txtPassword").value = "safvan542"; document.forms["logInForm"].submit(); console.log("Login submitted!"); //After the form is submitted, wait 3s and click on the link: setTimeout(function(){document.getElementsByTagName("a")[20].click();},3000); }); setTimeout(function(){ page.render('hrtesttime.pdf'); phantom.exit(); }, 15000); } });