Execute Javascript Click passing a variable

First off I’ll admit that I am a complete Javascript novice. After searching for a few hours through this forum and stack exchange though, I thought I would try asking for help here.

I’m trying to use KM to click a button on a Chrome page. There are 50 of the same button on the web page; the only difference being a variable gets passed to change the customer number. The link looks like this:

<a class=“btn btn-default btn-xs” ng-if=“customer.PartnerCanGuestAdminister && customer.CustomerStatus != ‘Closed’” ng-click="$ctrl.setGuestAdminHiddenValues(customer.CustomerNumber)" href=“javascript:__doPostBack(‘ctl00$ctl00$cphBMB$cphMB$ctl01’,’’)”>

I have a database that will be able to pass the customer.CustomerNumber. So what I’m looking for is what Javascript do I pass to Chrome from KM to simulate this button click? (This is assuming, that I will be passing it with the customer number. ie. “$ctrl.setGuestAdminHiddenValues(c6df0a01-921d-4997-a1cf-a79300e78c16)”

The Xpath example in this forum doesn’t work for me since I need to pass a variable and since this button uses a class instead of an ID. [WEB] Click on Link Using XPath [Example]

Any help you can offer would be much appreciated-

You can probably most easily do the action using the actions:Execute a JavaScript in Browser. The Keyboard Maestro variable values are available to the JavaScript (see the Using Keyboard Maestro Variables section).

Translating the code above into code that gets executed is where I got stuck.

Fortunately Keyboard Maestro offers about 100 different ways to skin a cat. The page with the buttons had a search field on it. I was able to paste into the search field an exact value which filtered the list with all the buttons. The button was then always in the exact same position. This allowed me to do a KM click action on it. Walaa!

2 Likes