Selenium Using current session to re-open the browser

2.7k views Asked by At

I am trying to open chrome, close it and then open it again using the same session. Is a thing like this even possible? I've looked through the internet/stackoverflow and tried using driver.Close(); but with no luck.

Anybody has some experience with this and mind helping me?

thanks

1

There are 1 answers

1
Subash J On BEST ANSWER

In Selenium Webdriver, a browser session can be closed using two webdriver commands: close() and quit(). The situations in which they are used are briefly explained below:

close() is a webdriver command which closes the browser window which is currently in focus.

During the automation process, if there are more than one browser window opened, then the close() command will close only the current browser window which is having focus at that time. The remaining browser windows will not be closed. The following code can be used to close the current browser window:

driver.close() //where, ‘driver’ is the Webdriver object.

quit() is a webdriver command which calls the driver.dispose method, which in turn closes all the browser windows and terminates the WebDriver session.

If we do not use quit() at the end of program, the WebDriver session will not be closed properly and the files will not be cleared off memory. This may result in memory leak errors.

The following code can be used to close all the browser windows:

driver.quit() //where, ‘driver’ is the Webdriver object. If the Automation process opens only a single browser window, the close() and quit() commands work in the same way. Both will differ in their functionality when there are more than one browser window opened during Automation.

Source: Reference link