Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. WebDriver
  3. Reference
  4. Errors
  5. Invalid session ID

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.

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

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp