0

In Our application while testing Manually we clear Cookies (Ctrl+Shift+Del), How can I automate this step?

Note: We are using Java

2 Answers 2

2

You can delete cookies using cookiename and all cookies alltogether.

To delete a particular cookie , use this

driver.manage().deleteCookieNamed(cookiename);

Python version of this method is

driver.delete_cookie(cookiename)

To delete all cookies at once

driver.manage().deleteAllCookies();

Python version for the same above is

driver.delete_all_cookies()

These are same for all browsers.

6
  • A small warning is that these look like non blocking methods - stackoverflow.com/questions/27504358/…
    – John
    Nov 21, 2016 at 13:51
  • Also, deleteAllCookies will only delete cookies under the domain of currently opened page. Jan 3, 2017 at 7:36
  • @KenstonChoi Yes, right!! How to delete from other domains as well?? Apr 7, 2017 at 9:10
  • @Pranav-BitWiser, some sites suggest that the browser has to visit these domains individually and delete the cookies. The easiest is to just launch a new browser session. Apr 7, 2017 at 11:07
  • @KenstonChoi Does this means that launching a new session will automatically deletes all cookies? Apr 7, 2017 at 13:25
1

You can use Selenium methods to clear the cookies.Here is the example

driver.manage().deleteAllCookies();
2
  • Is this Same for all Browsers? Feb 15, 2016 at 7:21
  • 1
    yup, same for all for browsers
    – QAMember
    Feb 15, 2016 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.