How to access the URL of a page recently opened by macro?

Hi,

I have a page with a list of links and want to create a macro like this (pseudocode):

open page "links"
FOREACH (links, counter=1) {
    open link xpath/to/link/$counter
    copy the URL of the new page
    go back to / open page "links"
}

(I need to open every single link, since the URLs are generated onClick.)

What I’ve tried:

{
  "Name": "MyMacro",
  "CreationDate": "2021-11-15",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://foo.com/links",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "click",
      "Target": "xpath=//...[${!LOOP}]/div/div[1]",
      "Value": "",
      "Targets": [
        "xpath=...",
        "xpath=...",
        "css=#links-table > div > ... > div"
      ],
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "${!URL}",
      "Value": "!csvline",
      "Description": "URL"
    },
    {
      "Command": "csvSave",
      "Target": "my-urls.csv",
      "Value": "",
      "Description": ""
    }
  ]
}

The problem is, that the macro copies every time the URL of the main page with the links – and not the URLs of the target pages.

How to access the URLs of the target pages?

Save it in csv and after you can open it

Thank you, but have you really read my question?..

Yes i read and i suggest best solution

Your macro after opened a page can save the url in a csv and you can open in any time, this is the best solution for your job.

After your macro open url you can save it in csv (2 commands to add in your macro) and you have always available the url used from your macros.

Ui vision have not a history of URLs visited.

Thanks for the fast reply! The problem is NOT the storing URLs in the CVS file. It works fine. The problem is, that the macro copies (and stores in the next step) only the URL of the “main” page.

There is a “main” page with a list of links. (Constraint: I cannot grab the URLs directly from these links, so I need to open them first and copy the links from the address bar.) The macro should go through the list, open every link, copy the URL from the address bar, and save it in CSV. Instead it copies every time the link of the “main” page. So, what I’m getting now is a list like:

URL
http://foo.com/main-page-with-the-list-of-links
http://foo.com/main-page-with-the-list-of-links
http://foo.com/main-page-with-the-list-of-links
...

instead of

URL
http://foo.com/page-a
http://foo.com/page-b
http://foo.com/page-c
...

It only works as expected, if I execute the macro step by step (by clicking “Step”, “Step”, “Step” instead of “Play Macro”).

Your macro is wrong because you use variable ${!URL} in wrong way

{
“Command”: “store”,
“Target”: “${!URL}”,
“Value”: “!csvline”,
“Description”: “URL”
},

This can be used ONLY to save the url opened by ui vision (not clicked with a button), this command can be used only when you use open command in ui vision.

Alternative solution is use another command that can save current utl in browser

{
  "Command": "executeScript",
  "Target": "return (window.location.href)",
  "Value": "href",
  "Description": ""
},

Warning can NOT be use with sandbox.

With this you can save every url opened in your browser.

Thanks a lot for sharing, Very helpful and informative for www.mybalancenow.com.