How to get the current URL in Robot framework?
Asked Answered
A

4

3

When the 'apply' link is clicked, it opens a new browser in Robot framework. How to get current url of that page? Here is the code:

Open Server     
Set Browser Implicit Wait   60  
Go To   ${server}/jobs  

Element Should Be Visible   xpath=.//*[@id='txtjobsearch']  

Input Text  xpath=.//*[@id='txtjobsearch']  ${job Title search}

Element Should Contain  xpath=(.//*[@class='clearfix tit-job']/div)[1]  ${Job title}

Element Should Be Visible   xpath=(.//*[@class='btn btn-sm btn-primary btnApply'])[1]   

Click Element   xpath=(.//*[@class='btn btn-sm btn-primary btnApply'])[1]

After this line, it opens a new window. How to get url of newly opened page and do actions like input text?

Set Browser Implicit Wait   20  

Wait Until Page Contains Element    xpath=.//*[@class='text-primary']   
Accommodation answered 5/8, 2015 at 13:14 Comment(1)
If give Get Location command is given it doesnt gives the url of the newly opened browser after the apply button is clicked .Accommodation
S
9

Try this:

${url}=   Get Location
Stephanistephania answered 5/11, 2016 at 13:18 Comment(0)
V
4

getting the current URL is easy using the Execute Javascript SeleniumLibrary keyword:

${url} =  Execute Javascript  return window.location.href;
Valentin answered 26/4, 2016 at 18:35 Comment(0)
L
1

Have you tried using the Select Window keyword?

http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html#Select%20Window

Click Link  popup_link  # opens new window  
Select Window   popupName       
Title Should Be Popup Title     
Select Window           # Chooses the main window again

It seems like you wish to verify the url of the new window which should be easily possible with the following:

Select Window | url=https://google.com

Obviously you need to replace the above url with what you're expecting. Let us know how you get on.

Leakey answered 5/8, 2015 at 14:12 Comment(4)
Actually my url will be changing .For Example https;//www.google.com/75 like this.so wat can i do. If url is constant i can directly give url=www.google.comAccommodation
google.com/job/35 like this it will be google.com/job/36 like this it will be changing.in this case how to get the url ?Accommodation
Can you explain more about the mechanism? For example is this clicking a 'user' or something? In which case you can grab the url from the link you click, then check that it is equal to the url in the new window? Or is this dynamically generated?Leakey
Select Window | url= , gives a message, invalid time string. what is that?Incredulous
A
0

If you are on a browser page after the robot tests open an authenticated URL (say google auth etc.) then GET LOCATION might return you a rather large string containing a lot of details.

However, after login if you click on any random element on the browser and then try GET LOCATION you will get the desired URL. Of course then you simply remove the previously clicked random item part from the returned string(URL).

Aho answered 2/7, 2024 at 12:54 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewBrowband

© 2022 - 2025 — McMap. All rights reserved.