0

I thought I knew how cookies work a little but I have doubts now.

  1. Have a python3 script to run a web browser (Google Chrome, for instance) controlled by Selenium. With options.add_argument("user-data-dir=<folder_full_path>") I set a folder for the browser folder. The folder does not exist yet.
  2. Run the script. Read cookies with driver.get_cookies() and get an empty list obviously. Stop the script with input()
  3. Manually visit www.dw.com; www.paris.com. Each greets me with a message and "have a cookie" button.
  4. Read cookies with driver.get_cookies() again and can see cookies.
  5. Quit the Selenium web browser and quit the Python script.

The Web browser folder is still there.

  • Run the Python script again. driver.get_cookies() gives an empty list.
  • Manually visit www.dw.com and www.paris.com They know me and I don't see any cookie messages (greetings).
  • Stop Python script, and quit the selenium-driven web-browser. I erase (or rename) the web-browsers folder and repeat actions 1-5.

So, I realize that visited websites remember "me" but when I start a new web browser session I can not read their cookies even though I visited websites before but they exist somehow. Where? How can I read their cookies? Why dw.com and paris.com can see their cookies saved before but I can not?

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24
C4H7Cl2O4P
  • 11
  • 7
  • Selenium by default enter Chrome as a Guest user. in order to log-in to your account you can see this answer: https://stackoverflow.com/a/67389309/19574650 – I.sh. Jul 25 '23 at 14:46
  • Thank you I.sh. I will study the link you gave. But how web-sites see their cookies and why can't I eventhough I'm a guest ? With chrome://version I took my user profile path which is "C:\Users\user_name_here\AppData\Local\Google\Chrome\User Data\Default". It is pretty the same as "Default" folder in mentioned above. What is the difference ? What if I set in '--profile-directory=...' "Default" folder from ? – C4H7Cl2O4P Jul 25 '23 at 15:39
  • Have you tried using incognito mode of your browser? Always worked for me – Knight Jul 26 '23 at 09:26
  • @Knight I don't know. What is it when I use Selenium ? How can It help ? – C4H7Cl2O4P Jul 26 '23 at 15:40
  • https://sqa.stackexchange.com/a/40777 This answer should help – Knight Jul 27 '23 at 05:51
  • @Knight It did not help. According to written there I have to see cookies invitation every time I visit the website but it does not happen as I wrote before. I see accept cookie button just once. Websites know me but I can see their cookies just once when I visit them for the first time. When I restart my script I can not see their cookies anymore but websites know that I visited them before. That is the question. – C4H7Cl2O4P Jul 27 '23 at 18:40

0 Answers0