Selenium Python Get Session Storage

Profile picture for user arilio666

To obtain the session storage in Python, use the execute_script method to execute JavaScript code in the browser environment.

from selenium import webdriver
from import ChromeDriverManager
from import By
from import Service

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

driver.find_element(By.CSS_SELECTOR, '#edit-name').send_keys('Monkey D Luffy')
sstorage = driver.execute_script("return sessionStorage;")
  • To run the JavaScript code return window, we utilize the execute_script sessionStorage function that returns the session storage object. 
  • The result is saved in the session_storage variable, which is subsequently printed.