Renumbering @id="element_xxx" numbers - Set Safari Field

Actions (v9.0.2)

I have an online form that has at least 100 different fields that need to be filled out by staff and or clients.
For me to test the form, I occasionally fill out the form to test the 'down stream' submission process.
To fill out the form automatically -
I have Set Safari Field actions that enter data to the specific field based on the element number (per screenshot)
The problem is, if I add another field anywhere in the form, the field id's of the fields after that change and I have to go thru numerous actions and renumber them.
I did make a macro that waits for a click, copies the number adds 1 to it and then replaces the original number with the new. That works but it's still very laborious.
The solution would be to have a method that would go thru the complete macro and add 1 to every "element_x" number in the 'set field' field.
Any help would be appreciated.

KM does not offer any Find and Replace for macros. It is possible to do this by editing the XML of the macro, but that is a complicated scripting process.

An alternative approach is to identify a different XPath that would work and not be impacted when you add another input element to the form. If you can post the URL or the HTML of the page, I'll take a look at it.

1 Like

@JMichaelTX I really appreciate you taking a look-see.
Please fill out the Candidate Intake Form here.

@troy, thanks for providing the URL. That is very helpful.

I think I can devise an XPath that will be independent of the element ID, and be based on the label below the form field. But it is complicated, and XPath is very tough to deal with, so it may take a few days.

Wouldn't it make more sense to give your input elements meaningful IDs that won't change when a new element is added?

The random IDs typically come when the form is generated on the fly by some form generating software - so it doesn't really understand the form enough to give semantically meaningful ids (and doesn't care enough to at least make the ids remain consistent).

wow @JMichaelTX I totally appreciate the offer but please do not spend an inordinate amount of time on it. It's not a 'mission critical' need. IF we need to add a field I'll just spend the couple hours and renumber the id's, and again, this is only so that I can tap a trigger and have KM fill out the whole form for me for testing. I could fill it out manually the once or twice I'll need to test the 'downstream' functionality. But really, I am grateful for your offer. many times over...

How would I do that? the form is an online form, not one that I create...
I appreciate the response

Sorry, I read your initial post as saying this was a form you were creating and therefore had control over the fields and what they were named. But if, as Peter points out, this is being auto-generated by some software or something, you probably don't have the ability to control field names.

@troy, thanks for being so considerate. While this will take a bit of time, it is also a learning opportunity for me. XPath is a very powerful tool, but also a challenge to learn. As with most things, the only way to really learn something is to do it, and do it often. :wink:

1 Like

@troy, OK, I think I have a solution. I only tested it on 3 fields. However, this works only for those fields whose label is immediately after the input field. I'lm still working on the other fields.

But please try this. The general form of the XPath is:
//span[label='LabelNameHere']/input

where you replace "LabelNameHere" with the actual label on the form.

For example:

image

Let me know if that is working for you. Meanwhile I'll keep researching how to set the other fields.

Woof, =), I will test this as soon as possible.
I've uploaded the complete macro if that is of any use for examining.
~ I'm a 'learner' too. I appreciate and respect your previous comment about learning.

RHS 2 Fill Out Cand Long.kmmacros (209 KB)

I made a duplicate of a short form we can test with. Candidate Short Form
I have not changed the order or added any new fields yet.
Just wanted to see if the new syntax filled out the correct field.
https://www.emailmeform.com/builder/form/g7KT77HJf7rdP4818y59VN

I'v focused on only changing the first and last name code as suggested.
It did not work. (edit: I just tried in Chrome also, it did not work)
Here is the macro I'm using for that.

Keyboard Maestro Actions.kmactions (781 B)

Here is the full macro - the candidate short version

RHS 1 Fill Out Cand Short TEST.kmmacros (11 KB)

Not sure why it did not work for you. I just tested in Safari, Chrome, and Brave Browser, and this worked in all three:

image

However, note I am using "Set Front Browser Field" rather than "Safari".

Here's my XPaths:
//span[label='First']/input
//span[label='Last']/input

Make sure you have the browser page selected (Frontmost) when you trigger the macro.

arg!, I was missing a slash before the input.... I apologize....
working fine for the text fields.
I tried to use a name for the dropdown and checkboxes and I'm sure you know, it didn't work.
I really appreciate your time and expertise.