user3303266
user3303266

Reputation: 371

RobotFramework: Switching window after clicking into a new window

Is there a way to adjust the focus (i.e bring to front) the second window after a click a link that goes to this second window in RobotFramework? I have some code that does screenshot after click and it only shows the first window

Click link  xpath=//*[contains(., "Download certificate")]
sleep  20
Select Window    Title=Certificate
Page Screenshot  Completion-Certificate   

I know that the title of the popup window is Certificate but i get error

ValueError: Unable to locate window with title 'Certificate'    

Upvotes: 0

Views: 28900

Answers (6)

atenache
atenache

Reputation: 39

${windows}=    Get Window Handles
log    les fenêtres
log    ${windows}
Switch Window    ${windows}[1]

Upvotes: -1

Raghwendra Sonu
Raghwendra Sonu

Reputation: 788

You can switch to multiple windows by title, URL or Window Handle ID. For this purpose use "Select Window" keyword from Robot Framework.

Example 1:

open browser  http://qaTechTesting.com Chrome
click element  (//img[@alt='Raghwen Linkedin Profile'])[1]
Select Window  Raghwendra Sonu

Example 2:

open browser  http://qaTechTesting.com Chrome
click element (//img[@alt='Raghwen Linkedin Profile'])[1]
@{list1}  get window handles
:FOR  ${Win} in ${list1}
\  Select Window   ${Win}

For more details read this: http://robotframework.org/Selenium2Library/Selenium2Library.html#Select%20Window

Upvotes: 0

ishaj
ishaj

Reputation: 101

Yes you can do it by adding the following script-

Switch Window  locator=NEW
//This will take you to the latest window launched.

It worked for me.

Upvotes: 6

user7940167
user7940167

Reputation:

Handle Lookup Window
Select Window    NEW      #comment: It will automatically move to new window
${tempB}=    Get Title
Log To Console    New window is : \ ${tempB}    # to verify the name in console
Select Frame    //*[@title='Search']            # optional sometimes elements are within frames ,so first need to access frame
Input Text    id=lksrch    hello
Click Element    //*[@value=' Go! ']
Unselect Frame                                  # going back to page
Select Frame    //*[@title='Results']           #selecting another frame
Click Element    id=jobdone 
Select Window                                    #once the jobdone button is clicked my pop up browser window is automatically get closed.so going back to parent browser.

note: line started using # are comments for understanding purpose only Thanks!

Upvotes: 1

Imran Chowdhury
Imran Chowdhury

Reputation: 79

I think for your case following will do the required:

Select Window    locator=Certificate

Upvotes: 0

Jeet
Jeet

Reputation: 183

I think, you are trying to test pop window which appears when you click on a link. You can use below solution,

Select Window    ${windowId}    # Focus popup/required window

Upvotes: 0

Related Questions