Software Development

What are the key differences between driver.close() and driver.quit() in Selenium WebDriver?

KI Asked by Kimberly Taylor · 16-06-2025
0 upvotes 16,682 views 0 comments
The question

I am currently refining my test automation framework and I'm confused about the best practices for terminating a session. I noticed that sometimes my browser windows remain open after a test suite finishes, while other times the entire execution stops abruptly. What exactly is the technical distinction between driver.close() and driver.quit()? Specifically, which one should I use to manage memory effectively when dealing with multiple browser tabs or windows during a heavy CI/CD pipeline execution?

3 answers

0
PA
Answered on 20-06-2025

The primary difference lies in the scope of the termination. driver.close() is used to close the current browser window or tab that has the focus of the WebDriver. If only one window is open, it might appear to end the session, but the WebDriver process itself may remain active. In contrast, driver.quit() is the "clean-up" command; it closes all associated windows, tabs, and most importantly, it terminates the WebDriver process and background services entirely. At iCertGlobal, we recommend using driver.quit() at the end of every test suite execution. This ensures that resources like chromedriver.exe are released from system memory, preventing "zombie processes" from slowing down your local machine or automation server.

0
ST
Answered on 22-06-2025

Are you specifically working with a multi-tab application where you need to close just the current child window and return control to the parent window, or are you looking for a global teardown method?

RI 23-06-2025

Steven, that's an important point for anyone handling pop-up windows. If you use driver.quit() while trying to just close a single pop-up, you'll kill the entire test run. For multi-window scenarios, you’d use driver.close() for the specific tab and then use driver.switch_to.window(original_handle) to keep the session alive. But once the final assertion is done, always follow up with driver.quit() in the @AfterTest or tearDown method to avoid memory leaks.

0
NA
Answered on 25-06-2025

Think of close() as closing a tab and quit() as closing the entire browser and stopping the engine. Always use quit() at the very end of your script to be safe.

KI 26-06-2025

I agree with Nancy. I’ve seen automation servers crash because developers only used close(), leaving hundreds of hidden driver processes running in the background. Using quit() is definitely the gold standard for stable automation.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session