Ever wondered why your automated tests leave browsers open and slow your computer down?
Closing browser (close vs quit) in Selenium Java - When to Use Which
Imagine you manually test a website by opening multiple browser windows and tabs to check different features. After testing, you try to close each window one by one by clicking the close button.
This manual closing is slow and easy to forget. Sometimes, windows stay open, consuming memory and causing confusion. You might accidentally close the wrong tab or leave some browsers running, which slows down your computer.
Using Selenium's close() and quit() commands lets you control browser windows precisely. close() shuts the current window, while quit() closes all windows and ends the session cleanly, saving time and avoiding leftover processes.
driver.close(); // closes current window only // but other windows stay open
driver.quit(); // closes all windows and ends session cleanlyIt enables fast, reliable cleanup of browser sessions, preventing resource waste and test interference.
When running automated tests overnight, using quit() ensures all browser windows close after tests finish, so the next day your system is ready and clean for new tests.
Manual closing of browsers is slow and error-prone.
close() closes one window; quit() closes all and ends the session.
Using these commands keeps tests clean and system resources free.