Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Select Window Robot Framework Python

In some cases, we need to to switch between windows on test automation. In the example below, we need to select different windows to do verification. 

In Robot Framework, Select Window keyword can switch between windows. 

 Windows Title Note
 Robot Framework  First Window
 After clicking on the Get Libraries link, the page displays as below    
 Robot Framework  First Window
 After clicking on the Builtit link, a new window displays as below    

 Robot Framework 

Documentation

Second Window

 This is a new 

windows 

 

 Clicking on the View button near Builtin,  a window displays below    
 Builtin  Second Window

 Robot Framework Code Implementation

Click here to see the final test result

 

*** Settings ***
Library           Selenium2Library

*** Test Cases ***
Manipulate Multiple Windows
    [Tags]    MultiWindow
    Open Browser    http://robotframework.org    firefox
    Maximize Browser Window
    ${Window1Title}=    Get Title
    Wait Until Element Is Visible    css=div.button.orange    10s
    Click Element    css=div.button.orange
    Wait Until Element Is Visible    link=Builtin
    Click Element    link=Builtin
    Comment    This is a new Window
    Sleep    5s
    Select Window    Title=Robot Framework documentation
    Wait Until Element Is Visible    //button[@value='BuiltIn']
    Click Element    //button[@value='BuiltIn']
    Sleep    5s
    Select Window    Title=Builtin
    Comment    Go back to the first window
    Sleep    5s
    Select Window    Title=${Window1Title}
    Page Should Contain Element    link=Builtin
    Close Browser

Run the above script and see the result. The test passed.  

======================================================
Robotexample.Multi Window Suite                          
======================================================
Manipulate Multiple Windows                        | PASS |
------------------------------------------------------
Robotexample.Multi Window Suite                    | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
======================================================
Robotexample                                       | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed

Starting test: Robotexample.Multi Window Suite.Manipulate Multiple Windows
20150331 10:51:33.118 :  INFO : Opening browser 'firefox' to base url 'http://robotframework.org'
20150331 10:51:42.738 :  INFO : ${Window1Title} = Robot Framework
20150331 10:51:42.895 :  INFO : Clicking element 'css=div.button.orange'.
20150331 10:51:43.422 :  INFO : Clicking element 'link=Builtin'.
20150331 10:51:48.932 :  INFO : Slept 5 seconds
20150331 10:51:49.410 :  INFO : Clicking element '//button[@value='BuiltIn']'.
20150331 10:51:54.983 :  INFO : Slept 5 seconds
20150331 10:52:00.373 :  INFO : Slept 5 seconds
20150331 10:52:00.868 :  INFO : Current page contains element 'link=Builtin'.
Ending test:   Robotexample.Multi Window Suite.Manipulate Multiple Windows

In summary, you can use Select Window keyword to manipulate multiple windows in Robot Framework