How to disable cookies in browser.

by (324 points)
+1 vote

How to disable cookies in browser?

Explain with code

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
+1 vote
For firefox:
FirefoxProfile profile = new ProfilesIni().getProfile("default");
profile.setPreference("network.cookie.cookieBehavior", 2);
driver = new FirefoxDriver(profile);
For Chrome:
ChromeOptions options = new ChromeOptions();  
Map prefs = new HashMap();  
prefs.put("profile.default_content_settings.cookies", 2);  
options.setExperimentalOptions("prefs", prefs); driver = new ChromeDriver(options); 
For IE:
String command = "REG ADD \"HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\ \" /v       1A10 /t REG_DWORD /d 0X3 /f";  
Hope that helps!
by (324 points)
That's Good! but what about safari browser?
by (171 points)
On safari you can not disable cookie. One way you can disable though, is by manually disabling cooking through the
Safari browser UI settings/preferences configuration (If that option is available). Then start Safari driver with that browser data profile (if not the default one starts).
by (324 points)
Ok. i got it.