Browser Cookies and Windows Command

HTTP Cookie is also called a web cookie, a browser cookie, or an Internet cookie. A cookie is a small piece of data that is sent from a website and stored in your computer. Cookies are mostly used to recognize the user and load the stored information. So basically, it is comprised of information about the user and their preferences.


Selenium web driver can perform the required task with respect to browser cookies

1. Get Cookies

This method is used to get all the list of cookies stored in the web browser.

driver.manage().getCookies();
 

2. Add Cookie

This method is used to add a specific cookie into cookies. If the cookie’s domain name is left blank, then cookie is assumed to be domain of the current document.

Cookie name = new Cookie(“cookie”, “12345678”);
driver.manage().addCookie(name);
 

3. Get Cookie Named

This method is used to get a cookie of the specific name.

driver.manage().getCookieNamed(“cookie”);
 

4. Delete Cookie Named

This method is used to delete the cookie of specific name from the current browsing domain.

driver.manage().deleteCookieNamed(“cookie”);
 

5. DeleteAllCookies

This method is used to deletes all the cookies of the current browsing domain.

driver.manage().deleteAllCookies();