How to annoy your friends on WhatsApp?

How to annoy your friends on WhatsApp?

Spamming WhatsApp messages using selenium and python.

Ajay Galagali's photo
Ajay Galagali

Published on Jun 23, 2021

3 min read

There are various ways to annoy your friends but being a programmer(); I should do it with my weapon known as CODE. 👨‍💻

Let's dive into it. 😁

We will be using python as a programming language and selenium to automate messaging.

Step 1: Download Chromedriver

Use this link to download ChromeDriver and extract the zip file.
Note: Download according to the version of Chrome installed on your system.

Step 2: Install Selenium Package

We need to install the selenium python package.
Open the terminal and run the command pip install selenium.

Learn more about Selenium here

Step 3: Programming

Time to code (); 😉


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

# About Selenium - https://www.selenium.dev/

# Getting Chrome Driver
driver = webdriver.Chrome(r"D:\Softwares\chromedriver_win32\chromedriver.exe") #put path of chromedriver.exe
driver.get('https://web.whatsapp.com/')

# Number of messages you want to spam
MESSAGE_COUNT = 10

# Sends Message
def sendMessage(msg):
    # Entering message in chat box
    WebDriverWait(driver, 100).until(
        EC.element_to_be_clickable((By.XPATH, '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]'))).send_keys(msg)

    # Clicking SEND button
    WebDriverWait(driver, 100).until(
        EC.element_to_be_clickable((By.XPATH, '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]'))).send_keys(
        Keys.RETURN)

flag = True

while flag:
    name = input("Enter Contact Name (Type \'exit\' to end the program) :") #type exit to end program

    if name == "exit":
        flag = False
    else:
        # How to get XPath of HTML element? -
        # Learn at https://ajaygalagali.hashnode.dev/how-to-get-xpath-of-html-element

        # To know more about XPATH visit - https://developer.mozilla.org/en-US/docs/Web/XPath

        # Clicking on Search
        WebDriverWait(driver, 100).until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="side"]/div[1]/div/label/div/div[2]'))).click()

        # Entering contact name
        WebDriverWait(driver, 100).until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="side"]/div[1]/div/label/div/div[2]'))).send_keys(name)

        # Opening chat of contact
        WebDriverWait(driver, 100).until(
            EC.element_to_be_clickable((By.XPATH, '//*[@id="side"]/div[1]/div/label/div/div[2]'))).send_keys(
            Keys.RETURN)

        # Spamming messages
        for i in range(MESSAGE_COUNT):
            sendMessage(i)

        sendMessage("These messages are sent by Python Program!")
        sendMessage("Learn here: https://ajaygalagali.hashnode.dev/")

See to it that package is imported successfully.

Step 4: Sending messages

  • Run the program
  • WhatsApp Web will be opened in the new Chrome Browser window.
  • Scan the QR code by your smartphone WhatsApp app to log into your account.

WhatsApp Web QR Code

  • Enter the contact name you want to send messages to

Enter the contact name you want to send messages to

  • Selenium will search the contact, types the messages, and sends them automatically.

Output of the program

  • Here, I sent 11 messages for demo purposes. You can send 1000s of messages too.

  • You can change the variable MESSAGE_COUNT in the program to any number, that number of messages will be spammed to your friend.

👨‍⚖️ Conclusion

Are they gonna get annoyed by just 11 messages? No way!
Listen to my story! I programmed to send 10k messages to my close friend's group. Around 50 messages were sent into the group and admin kicked me out of the group 😂. Admin with a brain! 👏. Well, title should be How to get kicked out of WhatsApp group without being mean? 😁

removed from group

lol xD


🤝 Thank You

Keep annoying friends 😉

 
Share this