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.

I have implemented the executeScript as shown above, but the results never change when I change pages and executScript. The results look very similar to the picture like:

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

With the links all being the first page url not the current one. Has this been broken somehow or am I implementing it incorrectly? My partial code looks like:

{
  "Command": "waitForPageToLoad",
  "Target": ".",
  "Value": "",
  "Description": ""
},
{
  "Command": "pause",
  "Target": "2000",
  "Value": "",
  "Description": ""
},
{
  "Command": "XClick",
  "Target": "PDFIcon2_dpi_126.png",
  "Value": "",
  "Description": ""
},
{
  "Command": "executeScript",
  "Target": "return (window.location.href)",
  "Value": "href",
  "Description": ""
},
{
  "Command": "pause",
  "Target": "2000",
  "Value": "",
  "Description": ""
},

When I measure href in the variables it never changes with the XClick command that changes the web page. Any idea how I can move forward, or some alternate proven method?