Skip to content

How to load cookies in SeleniumBase #2705

Answered by mdmintz
joako233 asked this question in Q&A
Discussion options

You must be logged in to vote

The SeleniumBase cookie methods for the SB() syntax format:

sb.save_cookies(name="cookies.txt")
sb.load_cookies(name="cookies.txt")
sb.delete_all_cookies()  # Duplicate: self.clear_all_cookies()
sb.delete_saved_cookies(name="cookies.txt")
sb.get_saved_cookies(name="cookies.txt")
sb.get_cookie(name)
sb.get_cookies()
sb.add_cookie(cookie_dict)
sb.add_cookies(cookies)

For more details on those, see seleniumbase/seleniumbase/fixtures/base_case.py.

Note that you have to be on the same origin/domain before you can add cookies to it.

This example logs in to a website, saves the cookies, opens a new browser, and loads the cookies to avoid logging in again:

"""A SeleniumBase test that loads cookie…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants