I need to add cookies via Webdriver using Firefox with Python. It works in normal mode, but not in private
mode.
from selenium import webdriver
capabities = webdriver.DesiredCapabilities.FIREFOX
capabities.update({"javascriptEnabled":True})
firefoxProfile = FirefoxProfile()
firefoxProfile.set_preference("browser.privatebrowsing.autostart", True)
driver = webdriver.Firefox(desired_capabilities=capabities, firefox_profile=firefoxProfile)
driver.get("http://httpbin.org/cookies")
driver.add_cookie({"name":"drag", "value": "lol", "domain": "httpbin.org"})
driver.get("http://httpbin.org/cookies")
No matter how many times I refresh the driver, cookies don't load. There is nothing present in document.cookie
in console log. It works fine in Chrome(not tested in incognito), and Firefox(non private).
I am aware in selenium private mode is redundant and I have read this SO question and also this.
But I cannot change much of the code. I need this feature to set cookie even in private mode in Firefox.
Firefox 66.0.1
Geckodriver 0.23.0 ( 2018-10-04)
Python selenium 3.14.1
Edit 1
I have tested with chrome(incognito) and it seems working
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")
capabities = webdriver.DesiredCapabilities.CHROME
capabities.update({"javascriptEnabled":True})
driver = webdriver.Chrome(desired_capabilities=capabities, chrome_options=chrome_options)
driver.get("http://httpbin.org/cookies")
driver.add_cookie({"name":"drag", "value": "lol", "domain": "httpbin.org"})
driver.refresh()
driver.get_cookies()
Chromium 73.0.3683.75 Built on Ubuntu , running on Ubuntu 18.04
ChromeDriver 2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d)
Python selenium 3.14.1
I could also find some issues with firefox in this answer but couldn't quite make sense out of it. The version of firefox used there is also old so there might be some changes in the present version.