Skip to content

Instantly share code, notes, and snippets.

@edrisranjbar
Created August 30, 2022 20:08
Show Gist options
  • Save edrisranjbar/363947bde1dced767616029e93d0fc98 to your computer and use it in GitHub Desktop.
Save edrisranjbar/363947bde1dced767616029e93d0fc98 to your computer and use it in GitHub Desktop.
Send whatsapp message using python and selenium
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(service=Service(
ChromeDriverManager().install()
))
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)
# Replace 'Friend's Name' with the name of your friend
target = '"Jhon Doe"'
# Replace the below string with your own message
message = "The Message"
x_arg = '//*[@id="pane-side"]/div[1]/div/div/div[7]/div/div/div[2]/div[1]/div[1]/span'
chat_title = wait.until(EC.presence_of_element_located((
By.XPATH, x_arg)))
chat_title.click()
inp_xpath = '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]'
input_box = wait.until(EC.presence_of_element_located((
By.XPATH, inp_xpath)))
input_box.send_keys(message + Keys.ENTER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment