Extract all href with same Text

Hello,

I understand that the storeAttribute command can be used to extract the url of an anchor. If a page has a link named “Click me”, all I have to do is:
storeAttribute | linkText=Click me@href | result
to store the URL in the result variable. This works perfectly as long as each link has a different linkText.
Now, if a page has 10 different links and all of them are called “Click me”, doing the previous command will only return the first on the list.
Is there a way to loop through all 10 links? I want to store all of them, not only the 1st one. I can get the total number of them using sourceSearch | Click me | howmany but that’s all. Maybe I don’t know how to use sourceExtract?
Thank you in advance

Good question. For the CLICK command you can use the click | linktext=hello@POS=2 (etc) method, but this is not supported by storeAttribute.

Solution: Use XPath:

(1) XPath of a link using link text: xpath=//a[contains(text(), 'Download')]

(2) XPath query to get n-th instance of an element: xpath=(//a[contains(text(), 'Download')])[2] (here n=2)

=> Now we can loop over the XPath with storeAttribute.

Test macro on 7zip.org:

    {
      "Name": "pos",
      "CreationDate": "2021-5-15",
      "Commands": [
        {
          "Command": "open",
          "Target": "https://www.7-zip.org/",
          "Value": "",
          "Description": ""
        },
        {
          "Command": "comment",
          "Target": "click // linkText=Download@POS=2",
          "Value": "",
          "Description": "recorded version"
        },
        {
          "Command": "comment",
          "Target": "click // xpath=//a[contains(text(), 'Download')]",
          "Value": "",
          "Description": "link text in xpath notation"
        },
        {
          "Command": "comment",
          "Target": "click // xpath=(//a[contains(text(), 'Download')])[2]",
          "Value": "",
          "Description": "get N-th match of the xpath (here: 2)"
        },
        {
          "Command": "times",
          "Target": "5",
          "Value": "",
          "Description": "get N-th match of the xpath (here: 2)"
        },
        {
          "Command": "storeAttribute",
          "Target": "xpath=(//a[contains(text(), 'Download')])[${!times}]@href",
          "Value": "url",
          "Description": ""
        },
        {
          "Command": "echo",
          "Target": "url of link${!times}=${url}",
          "Value": "green",
          "Description": ""
        },
        {
          "Command": "end",
          "Target": "",
          "Value": "",
          "Description": ""
        }
      ]
    }

Thank you very much, 1st method with click is perfect, for I can always click on it and get the !URL value