Skip to content

Instantly share code, notes, and snippets.

@Ramhm
Forked from deepak3081996/whatsapp.py
Created February 12, 2021 15:01
Show Gist options
  • Save Ramhm/8b643fbab5034232c2a6f2ba89fdfcf4 to your computer and use it in GitHub Desktop.
Save Ramhm/8b643fbab5034232c2a6f2ba89fdfcf4 to your computer and use it in GitHub Desktop.

Revisions

  1. @deepak3081996 deepak3081996 revised this gist Jan 21, 2018. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions whatsapp.py
    Original file line number Diff line number Diff line change
    @@ -13,17 +13,17 @@ def message(to,message=''):
    to - enter a name from your contacts it can be friend's name or a group's title.
    message - message to be deliever"""
    d = webdriver.Chrome(r'F:/chrome driver/chromedriver.exe') # directory to chromedriver
    d.get('https://web.whatsapp.com/') # URL to open whatsapp web
    wait = WebDriverWait(driver = d, timeout = 900) # inscrease or decrease the timeout according to your net connection
    d.get('https://web.whatsapp.com/') # URL to open whatsapp web
    wait = WebDriverWait(driver = d, timeout = 900) # inscrease or decrease the timeout according to your net connection

    message += '\nthis is a system generated message' # additional text to with your message to identify that it is send via software
    message += '\nthis is a system generated message' # additional text to with your message to identify that it is send via software

    name_argument = f'//span[contains(@title,\'{to}\')]' # HTML parse code to identify your reciever
    name_argument = f'//span[contains(@title,\'{to}\')]' # HTML parse code to identify your reciever
    title = wait.until(EC.presence_of_element_located((By.XPATH,name_argument)))
    title.click() # to open the receiver messages page in the browser
    title.click() # to open the receiver messages page in the browser

    # many a times class name or other HTML properties changes so keep a track of current class name for input box by using inspect elements
    input_path = '//div[@class="pluggable-input-body copyable-text selectable-text"][@dir="auto"][@data-tab="1"]'
    box = wait.until(EC.presence_of_element_located((By.XPATH,input_path)))

    box.send_keys(message + Keys.ENTER) # send your message followed by an Enter
    box.send_keys(message + Keys.ENTER) # send your message followed by an Enter
  2. @deepak3081996 deepak3081996 created this gist Jan 21, 2018.
    29 changes: 29 additions & 0 deletions whatsapp.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys

    def message(to,message=''):
    """this a simple function to send a whatsapp message to your friends
    and group using python and selenium an automated tool to parse the HTML
    content and to change the properties.
    paramters:
    to - enter a name from your contacts it can be friend's name or a group's title.
    message - message to be deliever"""
    d = webdriver.Chrome(r'F:/chrome driver/chromedriver.exe') # directory to chromedriver
    d.get('https://web.whatsapp.com/') # URL to open whatsapp web
    wait = WebDriverWait(driver = d, timeout = 900) # inscrease or decrease the timeout according to your net connection

    message += '\nthis is a system generated message' # additional text to with your message to identify that it is send via software

    name_argument = f'//span[contains(@title,\'{to}\')]' # HTML parse code to identify your reciever
    title = wait.until(EC.presence_of_element_located((By.XPATH,name_argument)))
    title.click() # to open the receiver messages page in the browser

    # many a times class name or other HTML properties changes so keep a track of current class name for input box by using inspect elements
    input_path = '//div[@class="pluggable-input-body copyable-text selectable-text"][@dir="auto"][@data-tab="1"]'
    box = wait.until(EC.presence_of_element_located((By.XPATH,input_path)))

    box.send_keys(message + Keys.ENTER) # send your message followed by an Enter