From post: How to ng-click an A directive in a PhantomJS test I understand I need to create my own function to click an element, but how do I use it?
The following code gives me error TypeError: 'undefined' is not a function (evaluating 'click(obj)')
var page = require('webpage').create();
var url = 'http://somesite.com/document.html';
page.open(url, function(status) {
page.evaluate(function() {
var obj = document.querySelectorAll('button')[0];
click(obj);
});
console.log(page.content);
phantom.exit();
});
function click(el){
var ev = document.createEvent('MouseEvent');
ev.initMouseEvent(
'click',
true /* bubble */, true /* cancelable */,
window, null,
0, 0, 0, 0, /* coordinates */
false, false, false, false, /* modifier keys */
0 /*left*/, null
);
el.dispatchEvent(ev);
}