MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / get_cookie

Method get_cookie

py/selenium/webdriver/remote/webdriver.py:842–860  ·  view source on GitHub ↗

Get a single cookie by name (case-sensitive,). Returns: A cookie dictionary or None if not found. Raises: ValueError if the name is empty or whitespace. Example: `cookie = driver.get_cookie("my_cookie")`

(self, name)

Source from the content-addressed store, hash-verified

840 return self.execute(Command.GET_ALL_COOKIES)["value"]
841
842 def get_cookie(self, name) -> dict | None:
843 """Get a single cookie by name (case-sensitive,).
844
845 Returns:
846 A cookie dictionary or None if not found.
847
848 Raises:
849 ValueError if the name is empty or whitespace.
850
851 Example:
852 `cookie = driver.get_cookie("my_cookie")`
853 """
854 if not name or name.isspace():
855 raise ValueError("Cookie name cannot be empty")
856
857 with contextlib.suppress(NoSuchCookieException):
858 return self.execute(Command.GET_COOKIE, {"name": name})["value"]
859
860 return None
861
862 def delete_cookie(self, name) -> None:
863 """Delete a single cookie with the given name (case-sensitive).

Calls 1

executeMethod · 0.95