- 1 Dump cookies from WebDriver
In Python,
json.dumps(driver.get_cookies()). In Java, serializedriver.manage().getCookies()to a JSON array of objects withname,value,domain,path,expiry. - 2 Normalise in the converter
Paste the array.
expirymaps toexpirationDate. Values<= 0become session cookies. Output JSON Array for Chrome, or switch to Netscape for curl. - 3 Add them back or send from curl
CookieMan Import on the test origin, or
driver.add_cookie()with the JSON objects, orcurl -b cookies.txtafter a Netscape export.
Selenium field names this parser accepts
| Selenium / WebDriver | CookieMan JSON | Notes |
|---|---|---|
name / value | same | Required |
domain | domain | Keep the leading dot if present |
path | path | Defaults to / |
secure / httpOnly | same | Booleans |
expiry or expires | expirationDate | Seconds; <= 0 → session |
sameSite | sameSite | Lax/Strict/None fold to lowercase enums |
> 1e12) are divided by 1000. That matches how some Java bindings leak Date.getTime() into expiry. Round-trip back into add_cookie()
import json
from pathlib import Path
# after converting to JSON Array in the tool:
cookies = json.loads(Path("cookies.json").read_text())
for cookie in cookies:
# Selenium rejects 'expiry' on session cookies — drop it
cookie.pop("hostOnly", None)
cookie.pop("session", None)
if cookie.get("expirationDate"):
cookie["expiry"] = cookie.pop("expirationDate")
else:
cookie.pop("expirationDate", None)
driver.add_cookie(cookie)