NoSuchWindowException: Message: no such window: target window already closed

Hi Team,

I am executing robot script on chrome browser.
My scenario-
step 1- Launch application
step 2- Click link -search inline (this is opening new browser window tab)
step 3- Click on X button on 2 tab
step 4- Application Closes second tab and opens new small window using window.open
step 5- I have to click on button of small window …which is not actual browser tab but its small opened window

When I was on first single tab and I have used code to switch to new window as below which working fine

switch window NEW

But in step #4 application actually closing second and opening small window so in above code I already switch to New window

As that 2nd tab is closed

I am again switching to New Tab using same code -but getting error

NoSuchWindowException: Message: no such window: window was already closed
(Session info: chrome=104.0.5112.102)

How I can switch back to default first window ?
How I can switch to new small window?

Hi @bk-user ,

Have you tried switching to MAIN (the original window) first, and then switching to NEW?

From Switch Window:

Switch Window	MAIN		# Select the main window

I’m guessing the error you’re getting is something about the selected window no longer exists?

This would be because as stated in the help for Switch Window “The previous windows handle is returned and can be used to switch back to it later.”, so as the window no longer exists so Switch Window is erroring on getting the handle to return.

You may also need to combine the Switch Window MAIN with Run Keyword And Expect Error so that it won’t error and then the script can continue to select the new window.

I haven’t tried any of this, so I hope it works for you.

Dave.