shortkeys icon indicating copy to clipboard operation
shortkeys copied to clipboard

Using JS to click button

Open ggbblimited opened this issue 3 years ago • 6 comments

I'm trying to get shortkeys to fire some JS to click a button on our warehouse management system.

One button is , there are other submit buttons on the page but only one with that value

<input type="submit" value="Create Shipment" class="btn btn-success pull-right">

The other is as below, the link on this changes for every order

<a class="btn btn-success" href="/Picking/DespatchOrder?OrderId=13413">Despatch</a>

Any help appreciated!

ggbblimited avatar Oct 17 '22 12:10 ggbblimited

I need the same thing! To click an Edit button.

nerdgirl avatar Oct 18 '22 14:10 nerdgirl

@ggbblimited According to a review this should work:

Just need to find that "button" from a page by right clicking it, inspect, copy JS Path, then use javascript document.querySelector("#NameofButton").click() and it worked magic for me!

I haven't gotten it to work...

nerdgirl avatar Oct 18 '22 19:10 nerdgirl

I found the issue with mine. It was a conflicting extension. :( But I need that extension! ACK.

nerdgirl avatar Oct 21 '22 22:10 nerdgirl

Andddd in this conversation with myself. I got it to work. Forgot that I was working on a Chromebook and my keys were different. Duh.

nerdgirl avatar Oct 21 '22 22:10 nerdgirl

Andddd in this conversation with myself. I got it to work. Forgot that I was working on a Chromebook and my keys were different. Duh.

I've got one going by class name

document.getElementsByClassName('btn btn-success pull-right')[0].click();

But I have another that shares the same class with other buttons, and the other script I have for finding by inner text isn't working

ggbblimited avatar Oct 22 '22 06:10 ggbblimited

Correction, fixed it.

/* Click button by innerHTML text */
function AutoClickBtnByValue() {
  var button = document.getElementsByClassName("btn-success");
  for (var i = 0; i < button.length; i++) {
    if (button[i].innerHTML.indexOf('Despatch') > -1) {
      button[i].click();
      console.log('Success! Clicked button' + i + ' with value: "click me now" ');
    }
  }
}
setInterval(AutoClickBtnByValue, 2000);

ggbblimited avatar Oct 22 '22 08:10 ggbblimited