Autoclicking a button with Javascript

There is a webpage that contains a form of username, password, and a submit button.

Each time I go into that webpage, I have to manually click the button to login (the creators of the webpage disabled automatic logging in even when the details are remembered by the browser).

I wish to enter automatically anyway. For that reason, I created the following script, but for some reason it doesn’t work. I wonder what I missed as it seems okay to me:

(function() {
let myButton = document.querySelector("[type=submit]");;

Wouldn’t it be something like:

window.onload = function() {;
1 Like

That did it. I wish I would know what was my mistake… Maybe the fact I passed myButton as an argument ti click()?

If so, why would this be problematic?

Because click is not a method defined in window.onload. window.onload is a method of window. And click is a native method of a button element.

1 Like

Thank you so much! I learned much from your answers and my Js logic improved!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.