- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Delete Cookies On All Domains using Selenium Webdriver.
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.
Syntax
driver.manage().deleteAllCookies();
Example
import java.util.Set; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class DeleteCookies{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/index.htm"); // wait of 4 seconds driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); // setting name and value for cookie Cookie c = new Cookie("test", "selenium"); Cookie r = new Cookie("subject", "Java"); // cookie addition driver.manage().addCookie(c); driver.manage().addCookie(r); // obtain the cookies Set ck = driver.manage().getCookies(); System.out.println("Cookie count: "+ck.size()); // delete cookies driver.manage().deleteAllCookies(); // obtain the cookies after delete Set ch = driver.manage().getCookies(); System.out.println("Cookie count after delete: "+ch.size()); } }
Output
- Related Articles
- How to save and load cookies using Python Selenium WebDriver?
- How to send cookies with selenium webdriver?
- Clear browser Cookies with Selenium WebDriver Java bindings.
- How can I delete all cookies with JavaScript?
- How to click on across browsers using Selenium Webdriver?
- Find elements using Selenium WebDriver?
- Clicking on elements within an SVG using XPath (Selenium WebDriver).
- How to get all options of a dropdown using Python Selenium webdriver?
- How to click Allow on Show Notifications popup using Selenium Webdriver?
- Using the Selenium WebDriver - Unable to launch chrome browser on Mac
- How to click on a link using Selenium webdriver in Python.
- Reading JavaScript variables using Selenium WebDriver.
- How can I verify Error Message on a webpage using Selenium Webdriver?
- Delete URLs with specific domains from MySQL database?
- Switch tabs using Selenium WebDriver with Java.

Advertisements