Chrome Driver - Allow All Cookies Setting

4,240 views
Skip to first unread message

Robert Sedgwick

unread,
Oct 11, 2020, 8:23:18 AM10/11/20
to Selenium Users
I need to allow all cookies when running tests with selenium + chrome driver.

I am trying to add this as a profile preference using ChromeOptions.AddUserProfilePreference


I'm not 100% sure what the preference name should be to allow all cookies. I have referenced this doc https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/pref_names.cc?view=markup

and have tried the following in my setup but its not having the desired effect. 


options.AddUserProfilePreference("profile.block_third_party_cookies", false);

and

options.AddUserProfilePreference("security.cookie_behavior", 0);


Here is my setup code


new DriverManager().SetUpDriver(new ChromeConfig());
var options = new OpenQA.Selenium.Chrome.ChromeOptions { };
options.AddArgument("–no-sandbox");
options.AddArguments("-disable-gpu");
options.AddArguments("-disable-dev-shm-usage");
options.AddArgument("-incognito");
options.AddArgument("-start-maximized");
options.AddUserProfilePreference("security.cookie_behavior", 0);
CurrentWebDriver = new ChromeDriver(options);

Jay Kay

unread,
Nov 27, 2020, 12:39:42 AM11/27/20
to Selenium Users
Hi,
I ran into the same issue. I think in ChromeDriver v86 they moved everything around. I found that using the following helped me:

options.AddUserProfilePreference("profile.cookie_controls_mode", 0);

I found the setting by checking the Chrome preferences file (in my case C:\Users\<user>\AppData\Local\Google\Chrome\User Data\Default\Preferences). I saved a copy with cookies blocked, then changed the setting to Allow all cookies and compared the two versions, and that highlighted the affected control for me.

Regards,
Jason

Reply all
Reply to author
Forward
0 new messages