How to close the new tab and return to the first tab in Robot Framework?

Viewed 7507

My test scenario clicks the button that follows to the new tab of the browser, after verifying that we got the right page I need to close this tab and return to the first tab. How could I close the actual tab? I tried to use Close Window, but it closes the entire browser?

2 Answers

This code can help you open new tab and close that's new tab by and return to your first tab.

*** Test Cases ***
T1
    Open Browser    ${URL}   ${BROWSER}
    click element   name=btn
    ${title_var}        Get Window Titles
    Select Window       title=@{title_var}[1]       
    close window

you can use below code to close active window and back to main window

${windowhandles}= Get Window Handles

Switch Window ${windowhandles}[1]

close window

Switch Window ${windowhandles}[0]

Related