I'm trying to click a button on a page using SlimerJS.
On the SlimerJS documentation, I see sendEvent(eventType, arg1, arg2, button, modifier)
which allows us to click on a given position by X and Y coordinates. (Doc here)
So, I tried getting these X and Y of a button coordinates the following way:
var webpage = require("webpage").create();
function clickButton(button)
{
var rect = button.getBoundingClientRect();
webpage.sendEvent('click',rect.left,rect.top,'left',0);
}
webpage.open(url).then(function(){
var button = webpage.evaluate(function(){
signInButton = document.querySelector("#signIn");
return signInButton;
});
clickButton(button);
});
This way, no error is thrown, but the button doesn't seem to get clicked. Is something wrong with this practice? Is there a better way? Is there a way to click a button or a link provided just it's ID or tag name?