Does anyone know if it's possible to Clear Browser Cookies for WebDriver before starting the automation? (Note: Not Selenium RC)
Navigate to the chrome settings page with Selenium by executing the driver. get('chrome://settings/clearBrowserData') . Click on the Clear Data button to clear the cache.
We can delete cookies on all domains with Selenium. The method deleteAllCookies is used to delete all cookies from the present domain. First, we shall add cookies, then get them and finally delete all the cookies.
Start at the Tools menu and select the Internet Options. To delete all cookies, click the Delete Cookies button.
Each cookie is associated with a name, value, domain, path, expiry, and the status of whether it is secure or not. In order to validate a client, a server parses all of these values in a cookie. When Testing a web application using selenium web driver, you may need to create, update or delete a cookie.
Yes, it's possible
driver.manage().deleteAllCookies();
Call it right after you are creating the new WebDriver instance.
WebDriver driver = new ChromeDriver(); driver.manage().deleteAllCookies();
You can also delete the cookies one by one
Set<Cookie> allCookies = driver.manage().getCookies(); for (Cookie cookie : allCookies) { driver.manage().deleteCookieNamed(cookie.getName()); }
Does this work for you?
driver.manage().deleteAllCookies();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With