Path: blob/main/files/en-us/web/webdriver/commands/closewindow/index.md
6540 views
------{{QuickLinksWithSubpages("/en-US/docs/Web/WebDriver/Commands")}}
The Close Window command of the WebDriver API closes the current top-level browsing context (window or tab) and returns with the list of currently open WebWindows. If it is the last window that is being closed, the WebDriver session will implicitly be deleted. Subsequent commands after the session is ended will therefore cause invalid session ID errors.
Syntax
| Method | URI template |
|---|---|
DELETE | /session/{session id}/window |
URL parameters
session id: Identifier of the session.
Errors
: Session does not exist.
: A user prompt, such as
window.alert, blocks execution of command until it is dealt with.
Example
Python:
C#:
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
Switch To Window command
Get Window Handle command
Get Window Handles command