Cookies in selenium python

  • A cookie is a piece of information from the website and saved by your web browser
  • Cookies are a way of remembering users and their interaction with the site by storing information in the cookie file as key-value pairs.
  • It stores the login information like user name/email and password
  • An HTTP cookie is also known as a web cookie, a browser cookie or an Internet cookie.
  • One website cannot access the cookies set by other websites

Database testing in Selenium python

  • Each cookie is associated with a name, value, domain, path, termination, and status of whether it is safe or not. We validate the cookie using selenium; selenium can parse all the cookies
  • When testing a web application using the Selenium, you may need to create, update, or delete a cookie to check the behavior of the website with and without cookies.
  • For example, when you automate e-commerce sites, you will set cookies for logins, products added to carts using cookies and the product you visited in or searched in past days.

Get Cookies in python

get_cookies() used to return the list of all cookies stored in the web browser.

# Go to the correct domain
# And now output all the available cookies for the current URL

get_cookie() used to return the specific cookie according to its name.


add_cookie() method is used to create and add the cookie.

# Go to the correct domain
# Now set the cookie. This one's valid for the entire domain
cookie = {‘name’ : ‘foo’, ‘value’ : ‘bar’}

Using delete_cookie() to delete a cookie according to its name.


delete_all_cookies() is used to delete all cookies.


Logging in Selenium python

About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions
  • Reply
  • Reply
  • troca foo por x e bar por y