karthika s
karthika s

Reputation: 31

How to get the current URL in Robot framework?

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']   

Upvotes: 3

Views: 33334

Answers (4)

Arshad Haroon
Arshad Haroon

Reputation: 1

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).

Upvotes: 0

Tobias Kreutzer
Tobias Kreutzer

Reputation: 91

Try this:

${url}=   Get Location

Upvotes: 9

hvelarde
hvelarde

Reputation: 2876

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

${url} =  Execute Javascript  return window.location.href;

Upvotes: 4

shicky
shicky

Reputation: 2126

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.

Upvotes: 1

Related Questions