How to get the current URL in Robot framework?

自闭症网瘾萝莉.ら 提交于 2019-12-24 03:41:23

问题


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

回答1:


Try this:

${url}=   Get Location



回答2:


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.




回答3:


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

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


来源:https://stackoverflow.com/questions/31833624/how-to-get-the-current-url-in-robot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!