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:
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.
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?
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.
var e = document.evaluate('//*[@id="whatever"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
Replace the //*[@id="whatever"] with the desired XPath.
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.
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:
Note only the first series of letters and numbers have actually changed.
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.