Search code examples
python-3.xseleniumselenium-chromedriver

How to make Selenium remember logins / sessions


I created this question to share some of the knowledge it was hard to find, at least for me.

I spent a lot of time searching for a way to make selenium store cookies and remember logins sessions so i woudnt need to scan a QR code every time selenium was launched in to the page i wanted.


Solution

  • With this code, i was able to save the chrome session in to a folder and use it every time ChromeDriver was launched. It saved me a lot of time and automated some tasks i had to do before.

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument(r"user-data-dir=" + "D:\py\Lib\site-packages\selenium\profile\wpp")
    options.add_argument('lang=pt-br')
    driver = webdriver.Chrome(options=options)
    driver.get('ENTER YOUR URL HERE WITH HTTP OR HTTPS')  
    

    If any one else would like to add answers and comments, please feel free to do it!

    I am new to StackOverflow and wanted to start contributing instead of just asking for help.