Reputation: 31
As with the title, how to clear browser cookies using Selenium Web Driver and C#?
IWebDriver driver = new FirefoxDriver();
driver.Manage().Cookies.DeleteAllCookies(); //delete all cookies
System.Threading.Thread.Sleep(5000);
I tried the above code but it is not deleting the session data.
Upvotes: 3
Views: 23239
Reputation: 131
You can clear cookies with the following:
driver.Manage().Cookies.DeleteAllCookies();
Keep in mind that this will only clear cookies from the current domain. We work with some sites on Azure AD. To properly clear the session at the end of my test I run the delete method, navigate to their domain, and run the delete method again.
Upvotes: 7
Reputation: 17553
I think the code is :-
driver.manage().deleteAllCookies();
not
driver.Manage().Cookies.DeleteAllCookies();
OR
Trial with same firefox profile:
driver.close();
driver = new FirefoxDriver(SeleniumObject.firefoxprofile); // Used the profile with which previous session was started.
driver.get(AppURL);
- Browser gets closed.
- The cookie is getting lost.
Trial with get(""):
driver.get("");
driver.get(AppURL);
Hope it will help you :)
Upvotes: 7