Ideally before collecting and printing the cookies you need to induce WebDriverWait for the visibility_of_element_located()
for a visible element and then collect the cookies as follows:
webdriver.get(url)
WebDriverWait(webdriver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "element_css")))
print(webdriver.get_cookies())
Or induce WebDriverWait for the element_to_be_clickable()
for an interactive element and then collect the cookies as follows:
webdriver.get(url)
WebDriverWait(webdriver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "element_css")))
print(webdriver.get_cookies())
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…