Selenium - Adding Cookies to Firefox Help

natmicon

BANNED
Joined
Dec 1, 2012
Messages
102
Reaction score
51
Alright, so I have a situation where I'm trying to keep consistant cookies across sessions for various users. With Chrome, it's super easy to add cookies. With Firefox, they don't want to add the cookie unless you've navigated to the site the cookie is for (which is useless, since I want to keep it consistant) and they don't seem to allow the leading . which so many cookies use now.

So if I go to the site, it gives an exception ".domain.com" when I try to load the cookie.

Is there any way around this to force Firefox to accept the leading . for subdomains in cookies?

If not, is there a way to have Chrome start a randomly generated profile each time with the exception of having a particular WEBAPP installed (not extension, I can't download the CRX that I can see)?
 
Why don't you load up Firefox with a pre-loaded profile, then add the cookies to the sqllite file that Firefox uses to store its cookies. Don't use Firefox directly to add the cookies, but add the cookies directly onto the database.
 
Why don't you load up Firefox with a pre-loaded profile, then add the cookies to the sqllite file that Firefox uses to store its cookies. Don't use Firefox directly to add the cookies, but add the cookies directly onto the database.

I hadn't thought about that. Selenium creates a new, temporary profile for each session. I would think using the same profile would be a footprint for this site. And I'll have thousands of accounts so it's impossible to maintain them all living on my hard drive. Is there a way to directly access the cookies file for the temporary Firefox profile that selenium creates?

If there isn't, is there a way to make sure the profile is completely reverted back to "virgin" on each run?
 
Never ever use newly created profiles with Selenium. You have to warm up your browser and add some history, as in some cookies. Therefor, you need to use profiles or cookies session.

I use Linux(Ubuntu) as my main machine so I have no idea where they are located on Windows(I suppose you are using Windows).

On ubuntu this is the location for the cookies.sqlite file:

Code:
~/.mozilla/firefox/*default*/cookies.sqlite

where *defaut* is the name of the profile.

You need to look up on Google, since I cannot post links here, where cookies.sqlite is located at. Use some sort of sqllite client to write queries directly to the database file and you should be good to go. Each profile is going to have its own cookies.sqlite file. If I were automating things via Selenium I would basically create the profiles by some sort of script, edit the cookies.sqlite file, and then start Selenium with that specific profile.

May the force be with you!
 
Back
Top