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 webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

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

driver.maximize_window()
driver.get('http://programsbuzz.com/user/login')
driver.find_element(By.CSS_SELECTOR, '#edit-name').send_keys('Monkey D Luffy')
sstorage = driver.execute_script("return sessionStorage;")
print(sstorage)
  • 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.