Overview - Closing browser (close vs quit)
What is it?
In Selenium WebDriver, closing the browser can be done using two methods: close() and quit(). The close() method closes the current browser window that the driver is controlling. The quit() method closes all browser windows opened by the WebDriver and ends the WebDriver session. Both are used to clean up after tests but behave differently depending on how many windows or tabs are open.
Why it matters
Without properly closing browser windows, tests can leave open browser instances consuming system resources, causing flaky tests or memory leaks. Using close() or quit() correctly ensures tests clean up after themselves, preventing interference with other tests and improving reliability. If you don't understand the difference, you might close only one window but leave others open, or quit the session too early, causing errors.
Where it fits
Learners should first understand basic Selenium WebDriver setup and how to open browser windows. After mastering browser control, they learn how to manage browser lifecycle with close() and quit(). Later, they will explore advanced session management and multi-window handling.