0

Since it's not possible via webdriver.get_cookies() to get all cookies (same domain and 3rd party cookies), I decided to read the Cookies file - which is stored in user profile path as SQLite.

But strangely I just saw that cookies are not being saved to this file in real time. I'm also not sure when the cookies are being stored. I have to wait about 10 seconds then the I can find all cookies there. Is there any idea how to read all cookies in real time for selenium web driver?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

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 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 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
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352