How to close child browser window in Selenium WebDriver using Java

0
0

Here I am getting some problem since a long time. And I couldn’t figure out that,can anybody would like to help me? … when i am going to switch new window ,after complete the task of new windows. I want to close that new window.and switch old window ,

so here i written like code:

// 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 error. Can anybody help me…?

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

  • You must to post comments
0
0

To close a single browser window:

driver.close();

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

driver.quit();
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website