0 votes
1 view
in Devops and Agile by (25k 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.

1 Answer

+1 vote
by (63.3k 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();

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...