- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to save and load cookies using Python Selenium WebDriver?
We can save and load cookies with Selenium webdriver in Python. A cookie is an information saved by the browser about the application. A cookie is stored in a key value pair.
It is generally used to hold the credentials of users. It also stores information about the user actions on the browser within the cookie file. We can add, obtain and delete cookies of the browser.
Syntax
c = driver.get_cookies() ck = { 'name': 'Selenium', 'value': 'Java'} driver.add_cookie(ck)
Example
Code Implementation
from selenium import webdriver driver = webdriver.Chrome (executable_path="C:\chromedriver.exe") driver.maximize_window() driver.get("https://www.tutorialspoint.com/index.htm") #get current cookies c = driver.get_cookies() print(c) #count cookies with len method print(len(c)) # load a new cookie ck = { 'name': 'Selenium', 'value': 'Java'} # save new cookie driver.add_cookie(ck) #get new cookies and total count after addition ch = driver.get_cookies() print(ch) print(len(ch))
- Related Articles
- How to send cookies with selenium webdriver?
- How to set Page Load Timeout using C# using Selenium WebDriver?
- Delete Cookies On All Domains using Selenium Webdriver.
- How to download any file and save it to the desired location using Selenium Webdriver?
- How to know the exact time to load a page using Selenium WebDriver?
- How to wait for iFrames to load completely in Selenium webdriver?
- Clear browser Cookies with Selenium WebDriver Java bindings.
- How to refresh a webpage using Python Selenium Webdriver?
- How to set window size using phantomjs and selenium webdriver in Python?
- How to get selected option using Selenium WebDriver with Python?
- Is there any way to load an extension in chrome browser using Selenium Webdriver?
- How to Verify Tooltip using Selenium WebDriver?
- How to upload files using Selenium Webdriver?
- How to click on a link using Selenium webdriver in Python.
- How to work with cookies in Selenium with python?

Advertisements