Invalid session ID
Theinvalid session ID error is aWebDriver error that occurs when the server does not recognize the unique session identifier. This happens if thesession has been deleted or if the session ID is invalid.
In this article
Example
>Explicit session deletion
A WebDriver session is explicitly deleted when quitting:
python
from selenium import webdriverfrom selenium.common import exceptionssession = webdriver.Firefox()print("Current session is {}".format(session.session_id))session.quit()try: session.get("https://mozilla.org")except exceptions.InvalidSessionIdException as e: print(e.message)Output:
Current session is 46197c16-8373-469b-bc56-4c4d9e4132b4No active session with ID 46197c16-8373-469b-bc56-4c4d9e4132b4
Implicit session deletion
The session can also beimplicitly deleted if you close the last window or tab:
python
from selenium import webdriverfrom selenium.common import exceptionssession = webdriver.Firefox()print("Current session is {}".format(session.session_id))# closes current window/tabsession.close()try: session.get("https://mozilla.org")except exceptions.InvalidSessionIdException as e: print(e.message)Output:
Current session is 46197c16-8373-469b-bc56-4c4d9e4132b4No active session with ID 46197c16-8373-469b-bc56-4c4d9e4132b4
See also
- List of WebDriver errors
- Session not created
- Related WebDriver commands: