ChromeOptions options = new ChromeOptions();
options.AddArguments("--user-data-dir=C:\\Users\\Myname\\AppData\\Local\\Google\\Chrome\\User Data");
options.AddArguments("--profile-directory=Profile 3");
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://web.whatsapp.com/");
How can I store the whatsApp login session, So that every time I run a program I don't need to scan the QR code again?
When you quit the webdriver, the cookies, cache, history, etc are deleted. So if you want to be already logged in when you start the webdriver, you have to use the cookies from a profile on the normal browser in which you are already logged in. To do so you have to:
In this way when you start the webdriver and load the page you will be already logged in.
Open chrome from the new desktop icon (mine is called "PythonSelenium - Chrome.exe") and login to instagram.
After you logged in, close the browser and open the properties of the new desktop shortcut. Take note of the name of the profile directory, which in my case is "Profile 3".
C:\Users\your_username\AppData\Local\Google\Chrome\User Data
, if you are not sure about it check where chrome is installed in your computer.Then run this code (remember to substitute Profile 3
with the name of your profile from step 3)
ChromeOptions options = new ChromeOptions();
options.AddArguments("--no-sandbox")
options.AddArguments("--remote-debugging-port=9222")
options.AddArguments("--disable-dev-shm-using")
options.AddArguments("--disable-setuid-sandbox")
options.AddArguments("--user-data-dir=C:\Users\your_username\AppData\Local\Google\Chrome\User Data");
options.AddArguments("--profile-directory=Profile 3"); // <-- substitute Profile 3 with your profile name
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://web.whatsapp.com/");