I am new to phantom.js and I am trying to go to the website page to click the link (which calls the AJAX function and changes the HTML document) using phantom.js.
Here is my code:
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);
});
I am very confused, as in my "real" function, calling click () raises this error, repeating it 3 times:
TypeError: 'undefined' is not a function of
phantomjs: //webpage.evaluate (): 3 phantomjs: //webpage.evaluate (): 1
ph.js: 121 null
TypeError: 'undefined' is not a function of
phantomjs: //webpage.evaluate (): 3 phantomjs: //webpage.evaluate (): 1
ph.js: 121 null
TypeError: 'undefined' is not a function of
phantomjs: //webpage.evaluate (): 3 phantomjs: //webpage.evaluate (): 1
ph.js: 121 null
In addition, if I comment on a line when sending a click, the action function no longer causes an error and returns a “click” to the console log well. But 3 times ...
What am I doing wrong?
Thanks in advance.