Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:SeleniumHQ Selenium Session Termination

From Leeroopedia
Knowledge Sources
Domains Browser_Automation, WebDriver, Resource_Management
Last Updated 2026-02-11 00:00 GMT

Overview

Protocol-defined procedure for ending a WebDriver session, releasing all associated browser and system resources.

Description

Session Termination is the orderly shutdown of a WebDriver session. The W3C specification defines two related operations: close() closes the current browser window (and ends the session if it was the last window), while quit() terminates all windows and the entire browser process. Proper session termination is critical for preventing resource leaks: orphaned browser processes, unreleased ports, and file handle exhaustion. The quit operation sends an HTTP DELETE to /session/{id}, which triggers the driver server to close the browser and clean up.

Usage

Always call quit() in a finally block or test teardown method to ensure clean resource release. Use close() when working with multiple windows and you want to close only the current one. Failing to call quit() leads to zombie browser processes that accumulate over time, especially in CI environments.

Theoretical Basis

# Pseudocode: Session Termination
close():
  1. Send DELETE /session/{id}/window
  2. If last window: session ends, browser process exits
  3. If not last window: only current window closes

quit():
  1. Send DELETE /session/{id}
  2. All browser windows close
  3. Browser process terminates
  4. Driver service process terminates
  5. Session ID becomes invalid

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment