I am a newbie in JavaScript and I currently have a script that presses a button for me. I tried it on one website and it worked great. Now I did the exact same thing on another website and it wouldn't work. The differences I could spot in HTML were that when I hovered over it with the element selector, one button had was formatted as button#id.class
and the other one was just button.class
. The two are also have some different attributes, but I think most of them are just website dependent.
So here is the HTML of the first button:
<button id="id" class="classname" type="button">Button</button>
Here is the HTML of the second button, I removed the svg data since I don't think it's necessary, I can add it later if you need it:
<button class="classname" aria-label="aria label" title="title"><svg></svg></button>
Here is the line of JavaScript that actually presses the button, at least the second one:
document.getElementsByClassName('classname')[0].click()