我无法使用phantomjs自动化访问第二页 [英] I cannot get access to the second page by using phantomjs automation
本文介绍了我无法使用phantomjs自动化访问第二页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法通过使用phantomjs自动化来访问第二页 显示错误 TypeError: undefined不是对象(评估'r [20] .click') 未定义:7 :8
I cannot get access to the 2nd page by using phantomjs automation showing an error TypeError: undefined is not an object (evaluating 'r[20].click') undefined:7 :8
在运行phantomjs代码时
while running the phantomjs code
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);
}
});
推荐答案
尝试以下代码:
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);
}
});
这篇关于我无法使用phantomjs自动化访问第二页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文