Search code examples
pythonautomationrobotframework

How to save part of a URL as a variable using Robot Framework


I wonder if you would be able to help

I have a page where I perform a save action and the resulting page gives me an ID in the URL

e.g. https://thiscouldbeanything.co.uk/Timesheet/Detail/115325

What I would like to do is take the 6 digit id at the end of the URL and save it as a variable for use later on in the test. I know you can use Get Location the to store the whole URL but I wondered if there was a way (probably a python keyword option) to take just the ID.

I thought maybe about a python function that would take the Get Location as an argument and then a way to chop the URL up and pass the id as a variable back, but I was unsure how.

Any help would be greatly appreciated.

Many thanks


Solution

  • here some python code can help you get your ID in your URL

    def getLastID(url):
        lastId=  url.rsplit('/', 1)[-1]
        return lastId