splinter icon indicating copy to clipboard operation
splinter copied to clipboard

adding cookies issues

Open jadeidev opened this issue 6 years ago • 1 comments

Hello, I am using Django with LiveServerTestCase. I was trying to load my chrome driver with a cookie that preloads a user session cookie. for example: cookie = {'path': '/', 'value': '9gl4p7wlrtgkw3dfer1vi2jievkks8f1', 'name': 'sessionid'} however, the cookie doesn't load properly, and the user is not logged in when i run

browser.cookies.add(cookie)
browser.reload()

When I inspected the code at splinter/driver/webdriver/cookie_manager.py I found that the way cookies are added is by

for key, value in cookies.items():
            self.driver.add_cookie({"name": key, "value": value})

resulting

{'name': 'path', 'value': '/'}
{'name': 'value', 'value': '9gl4p7wlrtgkw3dfer1vi2jievkks8f1'}
{'name': 'name', 'value': 'sessionid'}

which didnt really work. I have revised the add function such that a cookie dict is added as a whole using Selenium add_cookie function. This is the new function:

def add(self, cookies):
    if isinstance(cookies, list):
        for cookie in cookies:
            self.driver.add_cookie(cookie)
            return
    self.driver.add_cookie(cookies)

Hope this helps

jadeidev avatar Dec 11 '19 19:12 jadeidev

Fixed by #895

javascript-error avatar Jul 19 '21 18:07 javascript-error