Looping Through a Dynamic Range of Input Fields

I am trying to automate some feedback. The problem I am having is that the number of feedback items I can respond to will change dynamically.

For instance in the web form currently there are two items to leave feedback on (there could just as easily be one or fifty). If I look at the XPATH for an example it looks like this:


Thanks in advance for any guidance.


For each feedback input the number will increment so that the second instance would be:


How can I loop through these if I don't know how many items there may be?

You can store the number in a variable (eg Index), and then use C%Variable%Index% in the XPath (presuming it is directly in a Keyboard Maestro field that accepts token text, otherwise you can do the same with JavaScript, but the details are going to be different).

As far as knowing when to stop, you would have to check whether the element exists, and if not assume you have come to the end of it.

Hi Peter, Many thanks for the response. I have been able to set a counter and increment through it. I presume if I simply have "failure aborts macro" enabled for the incremented link this will signify the end. So for instance, if I set a repeat of 10 times and there are only 5 items the macro will abort when it can't find the sixth link.

One basic issue I am encountering is that when processing each item I need to go back to the previous screen, but either the back button is not available (not sure why) or clicking back takes me out of the website and to my initial "google" tab page. Any thoughts or articles you can point me to regarding this kind of browser navigation/issue.

Many thanks


Hey Keith,

Why not save the initial URL and then reset the page URL at need?


Ah I see what you mean. Thanks for the idea Chris, I'll give that a go.



1 Like