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

Method add_cookie

py/selenium/webdriver/remote/webdriver.py:881–899  ·  view source on GitHub ↗

Adds a cookie to your current session. Args: cookie_dict: A dictionary object, with required keys - "name" and "value"; Optional keys - "path", "domain", "secure", "httpOnly", "expiry", "sameSite". Examples: `driver.add_cookie

(self, cookie_dict)

Source from the content-addressed store, hash-verified

879 self.execute(Command.DELETE_ALL_COOKIES)
880
881 def add_cookie(self, cookie_dict) -> None:
882 """Adds a cookie to your current session.
883
884 Args:
885 cookie_dict: A dictionary object, with required keys - "name" and
886 "value"; Optional keys - "path", "domain", "secure", "httpOnly",
887 "expiry", "sameSite".
888
889 Examples:
890 `driver.add_cookie({"name": "foo", "value": "bar"})`
891 `driver.add_cookie({"name": "foo", "value": "bar", "path": "/"})`
892 `driver.add_cookie({"name": "foo", "value": "bar", "path": "/", "secure": True})`
893 `driver.add_cookie({"name": "foo", "value": "bar", "sameSite": "Strict"})`
894 """
895 if "sameSite" in cookie_dict:
896 assert cookie_dict["sameSite"] in ["Strict", "Lax", "None"]
897 self.execute(Command.ADD_COOKIE, {"cookie": cookie_dict})
898 else:
899 self.execute(Command.ADD_COOKIE, {"cookie": cookie_dict})
900
901 # Timeouts
902 def implicitly_wait(self, time_to_wait: float) -> None:

Calls 1

executeMethod · 0.95