How to clear cookies on already running browser instence in C#(or java)

53 views
Skip to first unread message

Kuldeep Singh

unread,
Sep 18, 2014, 4:26:59 AM9/18/14
to seleniu...@googlegroups.com
  I am doing below task-

1.I Created a simple firefox driver(named-Driver) using IWebDriver in c#
2.Then Run some test steps
3.Now I want to disable cookies after running some steps
4.I am trying this by using below line
       FirefoxProfile profile = new FirefoxProfileManager().GetProfile("default");
        profile.SetPreference("network.cookie.cookieBehavior", 2);
        IWebDriver driver2 = new FirefoxDriver(profile); (I think it is wrong)

Porblem - How can I set above profile object(for disable cookies) on already running 'Driver' object(not on driver2) in middle of testcase execution.


Expected output and What I see instead?

Cookies should be disable for running browser instance, but instead of disable cookies for running 'Driver' object it is opening new browser instance.


Selenium version:2.43.0.0
OS:Windows 8
Browser: firefox
Browser version: 31.0

Please someone help me as it is very urgent.

Robin Gupta

unread,
Sep 20, 2014, 2:25:31 PM9/20/14
to seleniu...@googlegroups.com
Try using -
driver.manage().deleteAllCookies

Sudhansu Sekhar panda

unread,
Sep 22, 2014, 5:44:14 AM9/22/14
to seleniu...@googlegroups.com
Hi Kuldeep,

As far my knowledge goes every time you run the script in FF it opens the default browser of the WebDriver not from the deafult profile of the browser...So for deleting cookies after navigating to any browser i am using the below code and it is working fine.

driver.manage().deleteAllCookies();

Thanks,

Sudhansu,
Reply all
Reply to author
Forward
0 new messages