MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / save_cookies

Method save_cookies

seleniumbase/fixtures/base_case.py:4757–4780  ·  view source on GitHub ↗

Saves the page cookies to the "saved_cookies" folder.

(self, name="cookies.txt")

Source from the content-addressed store, hash-verified

4755 return page_actions.save_page_source(self.driver, name, folder)
4756
4757 def save_cookies(self, name="cookies.txt"):
4758 """Saves the page cookies to the "saved_cookies" folder."""
4759 self.wait_for_ready_state_complete()
4760 cookies = self.driver.get_cookies()
4761 json_cookies = json.dumps(cookies)
4762 if name.endswith("/"):
4763 raise Exception("Invalid filename for Cookies!")
4764 if "/" in name:
4765 name = name.split("/")[-1]
4766 if "\\" in name:
4767 name = name.split("\\")[-1]
4768 if len(name) < 1:
4769 raise Exception("Filename for Cookies is too short!")
4770 if not name.endswith(".txt"):
4771 name = name + ".txt"
4772 folder = constants.SavedCookies.STORAGE_FOLDER
4773 abs_path = os.path.abspath(".")
4774 file_path = os.path.join(abs_path, folder)
4775 if not os.path.exists(file_path):
4776 os.makedirs(file_path)
4777 cookies_file_path = os.path.join(file_path, name)
4778 cookies_file = open(cookies_file_path, mode="w+", encoding="utf-8")
4779 cookies_file.writelines(json_cookies)
4780 cookies_file.close()
4781
4782 def load_cookies(self, name="cookies.txt", expiry=False):
4783 """

Callers

nothing calls this directly

Calls 3

get_cookiesMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected