Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

Here I am getting some problem for a long time. And I couldn't figure out that, can anybody would like to help me? ... when I am going to switch a new window, after complete the task of new windows. I want to close that new window. and switch old window, so here I have written the code like this:

// Perform the click operation that opens new window

String winHandleBefore = driver.getWindowHandle();

    // Switch to new window opened

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



    // Perform the actions on new window


    WebElement userName = driver.findElement("edit-name"));






    catch(Exception e)



        System.out.println("not close");


driver.switchTo().window(winHandleBefore);// Again I want to start code this old window

Above I written code driver.quit() or driver.close(). But I am getting an error. Can anybody help me...?

org.openqa.selenium.remote.SessionNotFoundException: The FirefoxDriver cannot be used after quit() was called.


1 Answer

+1 vote
by (62.9k points)
selected by
Best answer

To close a single browser window:


To close all (parent+child) browser windows and end the whole session:


If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s online Selenium certification

Browse Categories