Arshad Fahmy
Arshad Fahmy

Reputation: 11

How to start chrome browser in already logged in tab using chrome drivers via selenium in python

I need to API WhatsApp web using selenium and chrome drivers or other drivers but it is not possible to open an already scanned WhatsApp-web page. I need to scan every time I run the code. I need suggestion for selenium of any other alternatives for selenium

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time


browser = webdriver.Chrome(r"chromedriver.exe")
browser.get(https://web.whatsapp.com)

I tried 1)chrome default page as WhatsApp-web logged in 2)not possible to change the URL of WhatsApp web but it is not possible as WhatsApp is single paged website.
3)cant access logged in cache also

Upvotes: 1

Views: 616

Answers (1)

thesalah1212
thesalah1212

Reputation: 86

you just needs to scan the QR code for one time, using user-data-dir you are able to save your session in chrome profile and use it anytime

from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_argument("--user-data-dir=C:\\Users\\mywhatsapp")
whatsapp = webdriver.Chrome(executable_path=r'C:\Windows\System32\chromedriver.exe', options=options)
whatsapp.get("https://web.whatsapp.com/")

Upvotes: 0

Related Questions