How do I click an element in PhantomJS?
page.evaluate(function() {
document.getElementById(\'idButtonSpan\').click();
});
This gives
It's not pretty, but I've been using this to allow me to use jQuery for the selection:
var rect = page.evaluate(function() {
return $('a.whatever')[0].getBoundingClientRect();
});
page.sendEvent('click', rect.left + rect.width / 2, rect.top + rect.height / 2);
but you can always replace $(s)[0]
with document.querySelector(s)
if not using jQuery.
(It does rely on the element being in view mind, i.e. your viewportSize.height is big enough).