Selenium + Python · Lesson 14 of 43

0/43 done

Module 14: Selenium Setup

14. Browser Drivers, Setup & close() vs quit()

14 minlesson

Your task

Implement safe_quit_driver(driver):

  1. If driver is not None, call driver.quit().

Write it in the editor, then press Check answer (Ctrl + Enter).

quit() vs close()

  • driver.close(): Closes only the current window/tab. The browser session stays alive.
  • driver.quit(): Terminates the entire WebDriver session and cleans up the browser OS process.
python
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://targetqa.com")
driver.quit()

Key Takeaways & Walkthrough Summary

In this lesson, we install Selenium using pip, launch Chrome, Firefox, and Edge, and understand the critical difference between close() and quit(). Let's dive in!

Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

What happens if driver.quit() is omitted?

Orphaned browser processes remain active in memory, exhausting CPU and RAM on your test runners.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip