I would like to test a click event on an anchor tag triggers the right DOM transformations. What I see in the browser works and I've pretty much checked each line of my code returns what I want, except when I let PhantomJS do it, the expected DOM transformations don't seem to trigger.
Here is my code:
page.open(url, function(status) {
if (status === "success") {
var specifications = page.evaluate(function() {
var a = document.querySelector("a[href='#Specifications']");
var e = document.createEvent('MouseEvents');
e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
return document.querySelector("div#Specifications").innerHTML;
});
console.log(specifications);
phantom.exit()
} else {
phantom.exit(1);
});
});
I initially just called document.querySelector("a[href='#Specifications']").click();
with the same result. In my web browser, clicking on that link triggers the DOM transformations. I can't however reproduce it in PhantomJS.