Copy Webform Checkbox

I am trying to create a macro capable of copying/pasting all of the entered data from one webform to another (different) webform. The webforms both contain various text fields and checkboxes. I am trying to accomplish this in Google Chrome. So far, this is not a problem with text fields.

For text fields, I use the following process:

  1. I use the action ‘Set Variable to Google Chrome Field’ and point it to the appropriate text field to turn the text I want to copy from the 1st form into a variable.

  2. I use ‘Set Google Chrome Field to Text’ and point it to the appropriate field to paste the above variable into the 2nd form.

However, I cannot seem to find a way to copy the ‘status’ of checkboxes. In other words, if a checkbox is ‘checked’ in the first form, I need to be able to ‘check’ a certain box on the second form. Likewise, if it is ‘unchecked’ in the first form, I need to ‘uncheck’ a box on the second form. The problem is that I can’t find a way to ‘Set variable to CHECKBOX’. I also can’t seem to find an appropriate ‘If Then Else’ action to see if a checkbox is checked/unchecked. Entering a checkbox ID into the ‘Set Variable to Google Chrome Field’ does not appear to work either.

So, how do I get Keyboard Maestro to see if a webform checkbox is checked or unchecked, and turn that info into a variable?

Unfortunately my Javascript skills are non existent so I’m hoping there is a way to do this using KM actions. I would appreciate any help!

Get the XPath of the checkbox (in Safari, you inspect the element, and then can control click on the element in the displayed source and select Copy XPath. I presume there is a similar means in Chrome.

Then use the Execute JavaScript action, to execute the code:

var e = document.evaluate('//*[@id="whatever"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
e.value;

Replace the //*[@id="whatever"] with the desired XPath.

The result will be “true” or “false” I believe.

Thank you for your help Peter!

Unfortunately the result I am getting using that code is simply the 'name' of the checkbox, not a value. It does not appear to make any difference if I have the box checked or unchecked...in each case it only returns the name, in this case 'Acoustic'.

Is there a way of using this code to return an actual value for whether or not the box is checked or unchecked (i.e. 0 or 1). Here is a screenshot showing the results I am getting.

I noticed Keyboard Maestro can indeed 'see' what the status of the box is via the circled part of the below screenshots, so I'm guessing this is do-able?

I think it should possibly be e.checked instead of e.value in the JavaScript.

Great, changing ‘e.value’ to ‘e.checked’ did the trick!

Thank you!

The above Javascript works great…but I have a new problem. It appears the checkboxes I am copying from are dynamic and so their ID changes every single time I open a new form (even the same form). To be clear, the forms are a series of identical Zoho forms we use internally at work. I am not sure if this is within the scope of Keyboard Maestro, but is there a way to still get the status (checked/unchecked) of dynamic webform checkboxes if their ID’s keep changing?

To be clear, it is only the first part of the ID that changes each time I close/open a form. For example, the same checkbox on the same form (but opened at a later time) may appear as:

//*[@id=“RHL3WV_checkboxesEl_zc-Genre_3_0”]

OR

//*[@id=“V4R09R_checkboxesEl_zc-Genre_3_0”]

Note only the first series of letters and numbers have actually changed.

Thanks again for any help! I am in love with Keyboard maestro but the javascript stuff is a little over my head.

You may be able to use a different XPath - XPath can specify the targeted checkbox in a variety of different ways - by ID is the best when the ID is constant, but that doesn’t help you in this case. But you can also specify XPaths based on parent elements and locations within those parents (like a file system path).

In the web page, edit the element to remove the ID, and then copy the XPath and see if you get something useful. It may just reference a parent with a similarly dynamic ID, so you may have to repeat the process until you can get something that works.