Imagine there is an element #button1
on website which is watched by jQuery:
$('#button1').click(function(){
console.log("you clicked");
};
So how do I click this #button1
element via JavaScript console? Is there a command like click("#button1")
? Thanks.
Open your page. Right-click on any element and click Inspect or Inspect element, depending on the browser you're using. Right-click on the element's source code and choose Copy > Copy XPath or Copy > XPath, depending on the browser you're using.
The click() method simulates a mouse-click on an element. This method can be used to execute a click on an element as if the user manually clicked on it.
The HTMLElement. click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.
Apart from clicking on "More tools-> Developer Tools", we can also open the element box using the following options: Clicking the F12 key. Using keyboard shortcut, "Ctrl + Shift + i" or "Ctrl + Shift + c" on Windows Operating System.
You can trigger click functio like bellow
Using JQuery
$('#button1').click()
using simple JS
document.getElementById('button1').click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With