I have a UI page to test where there are is a lot of room for automation. For example there are buttons that might be clicked all at once or sequentially and they perform some action. Therefore I tried automating the clicking with JS and jQuery, starting from Firefox and moving on to chrome (using greecemonkey and tempermonkey).
The transition from these two browsers was not as easy as I first thought as what seems to be not working is the .click(); method on chrome (at least trying to click some buttons from browsers console).
A simpliefied version when run from browsers console (chrome) and firebug (firefox):
$(".div.tab-pane.active").find(".delete-link").click();
- On chrome: just prints out an array of matched elements;
- On firefox: actually clicks the link;
Running:
$(".div.tab-pane.active").find(".delete-link").text();
Indicates that the elements are targeted correctly.
Questions:
Do I need to attach an event listener with .on() method to the button I try to click? As I tried this code and it still is not working:
function notify() {
$(".div.tab-pane.active").find(".delete-link").click();
alert( "clicked" );
}
$(".div.tab-pane.active").find(".delete-link").on( "click", notify );
or
$(".div.tab-pane.active").find(".delete-link").on("click", function(){
alert("clicked");
});
$(".div.tab-pane.active").find(".delete-link").click();
// causes a stack overflow
Why does it work with Firefox (both from firebug and greecemonkey) and not in chrome? What is different in those two browsers that makes the working of .click() different?
How to make it work?