I am trying to load a cookie saved with selenium WebDriver in order to automatically login into GitHub account. Any ideas what i am doing wrong? This is the script output: selenium.common.exceptions.UnableToSetCookieException: Message: unable to set cookie
chrome.find_element_by_xpath("//*[@id='login_field']").send_keys("*********")
chrome.find_element_by_xpath("//*[@id='password']").send_keys("***********")
chrome.find_element_by_xpath("//*[@id='login']/div[4]/form/div/input[12]").click()
time.sleep(3)
save_cookies(chrome,"saved_cookies.txt")
chrome.quit
time.sleep(2)
chrome1 = webdriver.Chrome()
load_cookies(chrome,"saved_cookies.txt")
chrome1.get("https://github.com")
These are the functions I use:
def save_cookies(driver, location):
pickle.dump(driver.get_cookies(), open(location, "wb"))
def load_cookies(driver, location, url=None):
cookies = pickle.load(open(location, "rb"))
driver.delete_all_cookies()
url = "https://github.com" if url is None else url
driver.get(url)
for cookie in cookies:
driver.add_cookie(cookie)