Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
2.5k views
by The go-to Tester (324 points)

How to disable cookies in browser?

Explain with code

1 Answer

1 like 0 dislike
by The go-to Tester (181 points)
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!
by The go-to Tester (324 points)
That's Good! but what about safari browser?
by The go-to Tester (181 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 The go-to Tester (324 points)
Ok. i got it.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...