I\'ve this page. I need to trigger a click on the BUY NOW button on this page using AngularJS.
I\'ve tried these ways to click on this \"BUY NOW\" in content script(
What about Vanilla JS, noone prohibited?
Such as "onlick/click"?
function ae(a,b,c) {
if (a.addEventListener)
a.addEventListener (b,c,false);
else if (a.attachEvent)
a.attachEvent ('on'+b,c);
}
function re(a,b,c) {
if (a.removeEventListener)
a.removeEventListener (b,c,false);
if (a.detachEvent)
a.detachEvent ('on'+b,c);
}
Try with this code; it simulates a mouse left click on the element by a quick succession of mousedown, mouseup and click events fired in the center of the button:
var simulateMouseEvent = function(element, eventName, coordX, coordY) {
element.dispatchEvent(new MouseEvent(eventName, {
view: window,
bubbles: true,
cancelable: true,
clientX: coordX,
clientY: coordY,
button: 0
}));
};
var theButton = document.querySelector('ul form button');
var box = theButton.getBoundingClientRect(),
coordX = box.left + (box.right - box.left) / 2,
coordY = box.top + (box.bottom - box.top) / 2;
simulateMouseEvent (theButton, "mousedown", coordX, coordY);
simulateMouseEvent (theButton, "mouseup", coordX, coordY);
simulateMouseEvent (theButton, "click", coordX, coordY);