Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12171

The python selenium add_cookie operation failed, indicating unable to set cookie

$
0
0

It's like this. I want driver to add a set of cookies after accessing a webpage with slider verification,but it failed. I can't find the reason for it

error

code

from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.chrome.service import Servicefrom selenium.webdriver.chrome.options import Optionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport osdef get(cookie:str,link:str):    cookie = {c.split("=")[0]:"=".join(c.split("=")[1:]) for c in cookie.split(";") if c}    chrome_options = Options()    chrome_options.binary_location = "D:/chrome_bot/chrome-win64/chrome.exe"    chrome_service = Service("D:/chrome_bot/chromedriver-win64/chromedriver.exe")    driver = webdriver.Chrome(service=chrome_service,options=chrome_options)    driver.get(link)    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "body")))    driver.delete_all_cookies()    for key,val in cookie.items():        driver.add_cookie({'name':key,'value':val})    driver.get(link)    os.system("pause")

I browsed a large number of examples and documents, and I downloaded chrome and chromedriver from https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json and placed them in a fixed file directory. Then, when I called the add_cookie() function, an error occurred.


Viewing all articles
Browse latest Browse all 12171

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>