How to get a part of a URL?

Hi all,

I am testing a page that provides me a transaction id in the URL after the payment, and I can’t find a way to get this part in the URL and then save it as a variable.
Example: once it’s paid, an id is shown in the URL and I need that one to assert its inclusion on a different page.

Can anyone help me with that?
Thanks

Hi Thiago,

Which Library are you using? there are keywords like Get Url and Get Location that will give you the url of the current page.

Once you have the full url, probably the simplest solution would be to use Split String to break apart the url parts

Assuming your url looks something like this:

https://my.application.server/app/path/resultpage.php?var1=something&receiptno=A98732165&var2=paid

I would do something like this:

  • ${urlparts}= Split String on ? first, this will give you a list with the firs value being the page and the second being the parameters
  • ${params}= Split String on & for the second value from the list on the line above (${urlparts}[1]), this will give you a list of key value pairs
  • For ${param} in ${params}
    • ${key} ${value} = Split String on = for ${param}
    • If ${key} == receiptno
      • Set Test Variable $receiptno ${value}
      • Break (end the for loop, we got what we needed)

If this is something you need to do often, then make your own keyword, put all the values in a dictionary and return the dictionary from the keyword.

Hopefully this will give you the idea, it’s not working code but should explain the concept,

Dave.

1 Like

Hi Damies,
thanks for your reply.

I will try this and let you know if it works.

1 Like

You can create a custom function in python that will take your full URL from Get Url and then return the part from URL that you need, that part can be saved in a variable you want, Global, Suite etc.
Try to create a file CustomKeywords.py in your project and import it in the needed test file.

1 Like

Thanks, Vladislav!

I will try this and let you know if it works!

You’re welcome, use ChatGPT to a faster solution, with RF sometimes you need to customize some things ))

1 Like