Using selenium: How to keep logged in after closing Driver in Python
11,691
Solution 1
I tried on my Mac, below code and it worked perfectly fine, I don't need to login again
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=/tmp/tarun")
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://web.whatsapp.com/')
driver.quit()
For window you can try changing the path as below
options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\User Data")
Solution 2
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\User Data")
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://web.whatsapp.com/')
driver.quit()
Here it is for Windows. Works perfect on Python 3.6
Author by
Daniyal Tariq
Daniyal Tariq lives in Lahore and He is Software Engineer, Web Developer & Photographer. He is the Founder and CEO at DesireLinks.com. Hobbies are Programming, Singing, Sketching and Painting
Updated on June 22, 2022Comments
-
Daniyal Tariq almost 2 years
I want to get my Whatsapp web (web.whatsapp.com) logged in, at the second time opening the Whatsapp web on chrome driver. Following is my code based on Python need your help.
from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_path = r"chromedriver.exe" options = Options(); options.add_argument("user-data- dir=C:/Users/Username/AppData/Local/Google/Chrome/User Data"); #options.add_argument("--start-maximized"); driver = webdriver.Chrome(chrome_path,chrome_options=options); #driver = webdriver.Chrome(); driver.get('https://web.whatsapp.com/')