selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'cookie' while adding cookies using selenium webdriver


I am trying to loged in using cookies and my main goal is to skip log in page via selenium webdriver add_cookie method. I’ve created csv file with cookies. In csv I have 3 columns which are Name, Value, Domain and all cookies were already added in this file. But while running my code I see that webdriver can’t bypass login step and I am getting the below exception from selenium library.

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'cookie'

My code is below:

from selenium import webdriver
import time
from import Options
from import Service
from import ChromeDriverManager
import pandas as pd

options = Options()
options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"

link = "https://**********"

browser = webdriver.Chrome(options=options, 

def get_cookies_values(file):
    dict_reader = pd.read_csv(file, encoding='unicode_escape')
    list_of_dicts = list(dict_reader)
    return list_of_dicts

cookies = get_cookies_values('cookies.csv')

for i in cookies:



I’ve changed code and replaced encoding=’unicode_escape’ with encoding=’utf-8′. The reason of such changes is the fact that I found that if I am using encoding=’unicode_escape’, then nothing read from my file. I found it using print function. Due to this I’ve replaced the econding option to ‘utf-8’ and moreover I’ve tried with ‘utf-8-sig’ but now I am getting the another error which is below:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x85 in position 2391: invalid start byte

So, for some reason I can’t read my csv file. Could someone clarify for me why? And how can I provide cookies to my driver.


Instead of storing the within a csv file you can use to store the cookies once the user had logged into the website and retrive them later as follows:

Storing the cookies:

import pickle

# steps to login
pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))

Adding back the cookies:

cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:


You can find a couple of relevanr detailed discussion in:

Answered By – undetected Selenium

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published