0

I am trying to auto click a button on a page using code in a .js file. The button I want to click is: <input type="submit" class="btn btn-primary" value="Proceed to contract form">

Here is the javascript I am executing:

$(document).ready(function () {
    console.log(document.getElementsByClassName('btn btn-primary')[0].type);
       $('.btn btn-primary').click();
  });

The message pops up properly in console. I have also tried window.onload to no avail, and also tried document.getElementsByClassName('btn btn-primary')[0].click; Nothing I try seems to work and I am at a loss. I even tried putting in a delay prior to executing the click, but that did not help either.

Thanks in advance for the advice and your patience with a Javascript newcomer (I have about 300 lines of working code after first starting to learn about 2 weeks ago... fun!).

Zach
  • 1
  • See [here](https://stackoverflow.com/a/56074659) - `.btn btn-primary` selects an element with an ancestor of `.btn` with a tag name of `btn-primary`. If you want to select an element with multiple classes, use the query string `.btn.btn-primary` – CertainPerformance May 26 '20 at 15:17
  • Wow - that was a fast response! Thank you for the education! I was not yet aware of this syntax. Your suggestion resolved the problem with my code. – Zach May 26 '20 at 15:22

0 Answers0