Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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()) {

        driver.switchTo().window(winHandle);

    }

    // Perform the actions on new window

    driver.findElement(By.id("edit-name")).clear();

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

    userName.clear();

              try

    {

        driver.quit();

    }

    catch(Exception e)

    {

        e.printStackTrace();

        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.

closed

1 Answer

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

To close a single browser window:

driver.close();

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

driver.quit();

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

...