Cookies in selenium:

 

What is Cookie:

  • Cookie is a small amount of website and saved by your web browser.
  • Its purpose is to remember information about you, similar to the preference file created by the software application.
  • The most common purpose is to store login information for a specific site.
  • Some sites save both your username and password in a cookie, while others will only save your username.
  • Whenever you say, “Remember me on this computer,” check a box, then the website will successfully generate a login cookie after logging in.
  • Cookies are a way of remembering users and archiving the information in a cookie file as adding key values to their conversation with the site.
  • HTTP cookie is also known as a web cookie, a browser cookie or Internet cookie.
  • A text file exists in the client machine or PC’s web browser, which stores a bit of information.

 

Why Handle Cookies in Selenium?

  • Each cookie is associated with a name, value, domain, path, termination, and status of whether it is safe or not. To validate the client, a cookie parses all these values into a cookie.
  • When testing a web application using the Selenium Webdriver, you may need to create, update or delete a cookie.
  • For example, when automating online shopping apps, you need to automate many people such as test capture orders, order carts, payment information, order confirmation, etc.

 

Package:

 

Selenium WebDriver Commands For Handle Cookies:

 

Get Cookies: Using this statement is used to return the list of all cookies stored in the web browser.

 

Get Cookie by name: Using this statement is used to return the specific cookie according to its name.

 

Add Cookie: Using this statement is used to create and add the cookie.

 

Delete Cookie: Using this statement is used to delete a specific cookie.

 

Delete Cookie by name: Using this statement is used to delete a cookie according to its name.

 

Delete All Cookie: Using this statement is used to delete all cookies.

 

 

Example of Cookies in selenium: