Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WhatsApp without QR code scanning everytime through Selenium WebDriver

Is there any whatsapp or webdriver API to access WhatsApp web without scanning QR code everytime while accessing it using selenium and chrome webdriver in python?

like image 411
Shrey Avatar asked Oct 18 '25 13:10

Shrey


2 Answers

This is What you need. This code Read QR and store it in cookies

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

jokes = ["You don't need a parachute to go skydiving. You need a parachute to go skydiving twice.",
    "This is Test Message."]

options = Options()
options.add_argument("--user-data-dir=chrome-data")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome('/usr/local/bin/chromedriver', options=options)
driver.maximize_window()
driver.get('https://web.whatsapp.com')  # Already authenticated

time.sleep(20)

##################### Provide Recepient Name Here ###############################
driver.find_element_by_xpath("//*[@title='MyJakartaNumber']").click()

for joke in jokes:
 driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]').send_keys(joke)
 driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[3]/button/span').click()
 time.sleep(10)

time.sleep(30)
driver.close()
like image 94
Soroosh Gholami Avatar answered Oct 21 '25 03:10

Soroosh Gholami


Your "WhatsApp" and "QR Code" don't tell anything to me, however if you're testing an application which requires an extra action to sign in I don't think you will be able to perform it using Selenium as it's browser automation framework.

Web applications identify users via Cookies - special HTTP Headers containing client-side information. When you start a web browser via Selenium bindings - it kicks off a clean browser session which is not authenticated in "WhatsApp" (whatever it is)

The solutions would be in:

  1. Authenticate in WhatsApp manually, store your browser profile somewhere and start Selenium by pointing it to the earlier storied profile folder
  2. Authenticate in WhatsApp manually, store your browser cookies and use WebDriver.add_cookie() function to read the stored cookies into the current clean session
like image 42
Dmitri T Avatar answered Oct 21 '25 04:10

Dmitri T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!