Cookies in selenium python

  • Cookie is a piece of information from 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
  • HTTP cookie is also known as a web cookie, a browser cookie or Internet cookie.
  • One website cannot access the cookies set by other websites

Handling Cookie 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
driver.get("https://www.example.com")
# And now output all the available cookies for the current URL
driver.get_cookies()		

Get Cookie by name in python selenium

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


driver.get_cookie('foo')			

Add Cookie in python selenium

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


# Go to the correct domain
driver.get("https://chercher.tech")
# Now set the cookie. This one's valid for the entire domain
cookie = {‘name’ : ‘foo’, ‘value’ : ‘bar’}
driver.add_cookie(cookie)		

Delete Cookie in python

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


driver.delete_cookie(“foo?)			

Delete All Cookie in python selenium

delete_all_cookies() is used to delete all cookies.


								driver.delete_all_cookies()			
								

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
You can also share knowledge by Adding a topic here


Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Protractor Online Training : We have closed registration for training

Please do email to chercher.tech@gmail.com for any queries

If you already registered then please do check your email for the Webex link for the training starting from 15th Nov 2018
 
Join My Facebook Group
Join Group