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";
Runtime.getRuntime().exec(command);
Hope that helps!