target window already closed from unknown error: web view not found

1,049 views
Skip to first unread message

sreedeviv...@gmail.com

unread,
Sep 4, 2018, 1:57:54 AM9/4/18
to Selenium Users

String mainWindow = driver.getWindowHandle();

driver.findElement(By.xpath(pro.getProperty(""))).click();

for(String newWindow : driver.getWindowHandles()){

    driver.switchTo().window(newWindow);
    }


driver.close();

Log.info("Closing the current Opened Window - Invoice");
driver.switchTo().window(mainWindow); ---error in this line

I am getting error while switching to main window. error is like: org.openqa.selenium.NoSuchWindowException: no such window: target window already closed from unknown error: web view not found

i have tried switching to default window, commenting driver.close and adding thread.sleep also but issue not resolved.

Meenal Jain

unread,
Sep 6, 2018, 2:10:54 PM9/6/18
to seleniu...@googlegroups.com
Hi Sreedevi,

The error itself telling that the window you're trying to switch to is already closed and it happened when you switched between multiple tabs/windows through for loop and closed the tab/window you reached at last. So here your for loop reaching your main tab at last which you're closing once you're coming out of loop. To avoid closing of your main tab,put condition in for loop to check if it is your main tab, if it is so then don't switch to it. 
Please let me know if you find any difficulty doing this.

Thanks, 
Meenal


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/22e834e4-d221-4d00-994a-081446055117%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages