Selenium persistent cookies in python
I have a test case where the user disconnects the browser and reopens it to check that some login cookies are loading correctly.
browser.get("domain1.com")
cookies_domain1 = browser.get_cookies()
browser.get("domain2.com")
cookies_domain2 = browser.get_cookies()
//close browser
//re-open browser
browser.get("domain1.com")
for cookie in cookies_domain1:
driver.add_cookie(cookie)
browser.get("domain2.com")
for cookie in cookies_domain2:
driver.add_cookie(cookie)
But it doesn't look very good. I need cookies to load before the page is opened. Selenium seems to only allow cookies from this page to be added to this page!
Another way I tried to do this is to save the directory browser.profile.path
, back up and reconnect, transfer it to FirefoxProfile
which is passed to webdriver.Firefox(FirefoxProfile(path_to_directory_backup))
. Unfortunately this doesn't seem to save cookies.
source to share
No one has answered this question yet
See similar questions:
or similar: