Discussions » Development

Trying to make a script that automatically presses certain buttons

Me
§
Posted: 2018-01-10

Trying to make a script that automatically presses certain buttons

There are multiple buttons of this type Open as well as other buttons that do not say "Open", I would like to only click the ones that say "Open".
This is what I have so far:
var el = document.querySelector(".button");
if (el && (el.textContent.trim() == 'Open')) {
el.click();

The only issue is that this only takes the first button on the page, which is not an "Open" button. Is there an alternative to querySelector I can use? and would it be wise to use a while loop to click the rest of the buttons afterwards?

Post reply

Sign in to post a reply.