Selenium use of Firefox profile

Selenium indeed uses a copy of the profile, though that ought not to cause any problems. I think your issue has more to do with session cookies vs. persistent cookies.

On support.mozilla.org is a list indicating what information is actually stored in your profile. Note that cookies are among these, however session-cookies are not stored in cookies.sqlite which is the reason Selenium cannot rebuild your session since it does not appear in the profile.

Many sites, however, offer a remember-me or a stay-logged-in option on their login page which, if used, will store a persistent cookie by which the session can be restored. I used the following script to test this out with gmail,

from selenium import webdriver

url = "https://mail.google.com"
fp = webdriver.FirefoxProfile('/Users/<username>/Library/Application Support/Firefox/Profiles/71v1uczn.default')

driver = webdriver.Firefox(fp)
driver.get(url)

When I run this script after having logged into gmail with the stay-logged-in option enabled, then Selenium is able to access my inbox. If the stay-logged-in option is not enabled the session is destroyed upon closing my browser and thus Selenium cannot restore it either.

The screenshot below shows that session cookies are indeed not stored in cookies.sqlite and thus do not appear in the profile when used by Selenium.

Firefox cookies in cookies.sqlite and firebug

Leave a Comment