Skip to content

WebDevHubs

  • Home
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • Java
  • Selenium
  • PHP
  • Python
  • Programs
  • Toggle search form

How to delete all cookies in Selenium Java?

Posted on July 20, 2025July 20, 2025 By Admin No Comments on How to delete all cookies in Selenium Java?

To delete all cookies in Selenium Java, you can use the WebDriver method:

driver.manage().deleteAllCookies();

Explanation:

  • This method deletes all cookies associated with the currently loaded domain in the browser session.
  • It is commonly used to clear session data before or during a test to ensure a clean state.

Complete Code:

javaimport org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class DeleteCookiesExample {
    public static void main(String[] args) {
        // Set ChromeDriver path if needed
        // System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");

        WebDriver driver = new ChromeDriver();

        // Navigate to a website
        driver.get("https://www.google.com");

        // Delete all cookies
        driver.manage().deleteAllCookies();
        System.out.println("All cookies deleted.");

        // Close browser
        driver.quit();
    }
}

Additional notes based on sources:

  • Typically, you delete cookies after navigating to a website because cookies are specific to the domain loaded in the browser.
  • You can also delete specific cookies by name or by passing a cookie object if needed.
  • New WebDriver instances usually start with a fresh browser profile, which has no cookies, but deleting cookies can be useful during test steps to simulate fresh sessions or logouts.
Selenium Tags:Selenium-Java

Post navigation

Previous Post: How to Open and Close the Browser Based on User Input in Selenium Java?
Next Post: How to Set the size of window using Selenium Java?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • CSS
  • HTML
  • Interview Experience
  • Java
  • JavaScript
  • Lodash
  • PHP
  • Programs
  • Python
  • Selenium
  • Software Testing
  • Web Technologies
  • Web Templates

Recent Posts

  • Java ArrayList trimToSize() Method
  • Java ArrayList toArray() Method
  • Java ArrayList subList() Method
  • Java ArrayList spliterator() Method
  • Java ArrayList sort() Method

Recent Comments

No comments to show.

Important Pages

  • About Us
  • Contact Us
  • Terms of Use
  • Privacy Policy

Web Development

  • HTML
  • CSS
  • JavaScript
  • PHP

Programming Languages

  • Java
  • Python
  • PHP
  • Programs

Others

  • Selenium
  • Lodash
  • Java ArrayList
  • JavaScript Array Methods

Copyright © 2025 WebDevHubs.

Powered by PressBook Green WordPress theme