storeText only stores the first match?

I’ve got this step on my macro:

storeText | //*[self::h1 or self::h2 or self::h3] | getTxt
echo | ${getTxt}

When using Chropath, the xpath used on the step returns 15 or so matches but when running the storeText macro, it only gets the first match of the xpath.

Is this expected? I want to get all of the matches returned by the xpath.

I think that is by design. Can you add an index like ${i} to your locator and then loop over all matches?

Example: //*[@id=“country-list”]/li[ ${!loop} ]/a/img

This example is from here: QUERY: Can Kantu macro use to capture website info?

If your locators would be as follows:

//*[@id="country-list"]/li[1]/a/img (first match)
//*[@id="country-list"]/li[2]/a/img (2nd match)
//*[@id="country-list"]/li[3]/a/img (3rd match)

=> so we replace the 1,2,3… with the !loop variable:

//*[@id=“country-list”]/li[ ${!loop} ]/a/img

1 Like

Till try this and let you know the result. Thank you Ulrich!

Hi Ulrich, unfortunately this solution is not applicable to what I’m trying to achieve but is very helpful!

Thank you again!