Selenium Driver

nara_lee·2025년 4월 25일
1

🤖 What is driver in Selenium?

driver is a controller object that launches and automates a real browser instance (like Chrome, Firefox, etc.) via the Selenium WebDriver protocol.

For example:

driver = webdriver.Chrome()

This line:

  • Opens a Chrome browser window.
  • Allows your Python script to interact with the browser — navigate pages, click buttons, scrape elements, etc.

❌ What happens if you don't call driver.quit()?

If you don’t call driver.quit(), several issues can occur:

1. Zombie browser processes stay open

  • The browser window (Chrome, for example) might close visibly, but its background process might still be running.
  • Over time, this can consume a lot of CPU and memory, especially if you run the script multiple times.

2. Temporary files and sessions aren’t cleaned up

  • Selenium creates temporary data (cache, cookies, local storage).
  • Without .quit(), this data might not be deleted, causing unnecessary disk usage.

3. You risk hitting OS limits

  • Each new webdriver.Chrome() without a corresponding quit() adds to the number of open file handles and processes.
  • On Unix/macOS systems, you could hit Too many open files errors.

✅ Difference between driver.close() and driver.quit()

MethodWhat it does
driver.close()Closes only the current tab/window.
driver.quit()Closes all tabs/windows and ends the browser process. This is what you usually want at the end of a script.

🔚 In summary:

  • Always use driver.quit() at the end of your script to gracefully shut down the browser and clean up.
  • 🧠 driver is your interface to a real browser, giving you full control over it via Python.

본 후기는 [한글과컴퓨터x한국생산성본부x스나이퍼팩토리] 한컴 AI 아카데미 (B-log) 리뷰로 작성 되었습니다.

#한컴AI아카데미 #AI개발자 #AI개발자교육 #한글과컴퓨터 #한국생산성본부 #스나이퍼팩토리 #부트캠프 #AI전문가양성 #개발자교육 #개발자취업

1개의 댓글