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

Method add_cookie

py/selenium/webdriver/remote/webdriver.py:780–798  ·  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

778 self.execute(Command.DELETE_ALL_COOKIES)
779
780 def add_cookie(self, cookie_dict) -> None:
781 """Adds a cookie to your current session.
782
783 Args:
784 cookie_dict: A dictionary object, with required keys - "name" and
785 "value"; Optional keys - "path", "domain", "secure", "httpOnly",
786 "expiry", "sameSite".
787
788 Examples:
789 `driver.add_cookie({"name": "foo", "value": "bar"})`
790 `driver.add_cookie({"name": "foo", "value": "bar", "path": "/"})`
791 `driver.add_cookie({"name": "foo", "value": "bar", "path": "/", "secure": True})`
792 `driver.add_cookie({"name": "foo", "value": "bar", "sameSite": "Strict"})`
793 """
794 if "sameSite" in cookie_dict:
795 assert cookie_dict["sameSite"] in ["Strict", "Lax", "None"]
796 self.execute(Command.ADD_COOKIE, {"cookie": cookie_dict})
797 else:
798 self.execute(Command.ADD_COOKIE, {"cookie": cookie_dict})
799
800 # Timeouts
801 def implicitly_wait(self, time_to_wait: float) -> None:

Calls 1

executeMethod · 0.95