How to get current page's URL + how can I apply regex to a given variable

  1. I am trying to get the current page’s URL with the following code:

{
“Name”: “TEST”,
“CreationDate”: “2020-8-23”,
“Commands”: [
{
“Command”: “store”,
“Target”: “${!URL}”,
“Value”: “current_url”
}
]
}

It throws an error

It says “Internal variable “!URL” not supported”. I’ve tried searching through this forum but not finding the right solution.

  1. After getting that URL I want to apply a regex to it:

current_url.regex("/.com/(\w+)/")

Is there any way to apply a regex to an existing variable? I’m not finding any way to achieve this. All ways of applying the regex is on the source code.

Can someone please help me out with this?

To use command ${!URL} you must load before the url, after it works.

I use alternative solution to save current url in any time

{
  "Name": "Save_Current_Url",
  "CreationDate": "2020-8-23",
  "Commands": [
    {
      "Command": "executeScript",
      "Target": "return (window.location.href)",
      "Value": "executeScript_Sandbox_result"
    },
    {
      "Command": "echo",
      "Target": "${executeScript_Sandbox_result}",
      "Value": ""
    }
  ]
}
1 Like

This works great. Thanks for replying!

Hello,

I tried to use your solution to get el current url page, but it get the ui.vision popup url instead of the current url webpage tested ! How can I do to get the url webpage and not the ui.vision url please ?

{
“Command”: “executeScript_Sandbox”,
“Target”: “var currentPage = window.location.href; return currentPage;”,
“Value”: “currentPage”
},
{
“Command”: “echo”,
“Target”: “${currentPage}”,
“Value”: “”
}

I use this code and working

{
  "Name": "Save_Current_Url",
  "CreationDate": "2020-9-23",
  "Commands": [
    {
      "Command": "executeScript",
      "Target": "return (window.location.href)",
      "Value": "executeScript_Sandbox_result"
    },
    {
      "Command": "echo",
      "Target": "${executeScript_Sandbox_result}",
      "Value": ""
    }
  ]
}