DEV Community

loading...
Cover image for Making a Whatsapp Spammer Using Selenium and Python.

Making a Whatsapp Spammer Using Selenium and Python.

pranavviswanathan profile image Pranav Viswanathan Updated on ・2 min read

We all have had spamming wars on our group chats before, and they get tiring because of the sheer mundaneness of the task, resending a single message again and again. That's where automation steps in.

Selenium is a web testing library for the robot framework. We're going to be using it today.

  1. Install Selenium:
  • Open a command line with admin privileges.
  • Type in 'pip install selenium'
pip install selenium
Enter fullscreen mode Exit fullscreen mode
  1. Install Chrome Webdriver:
    • Identify the version of chrome you are using
    • Go to the chrome driver web page and download the required driver.
    • Here as I am using a Windows OS, I downloaded the Win32 zip file. Alt Text
  • After it has been downloaded, extract the .exe file and put it in a drive and file of your choice (It's important to remember where you have saved it).
  1. Check Environment:

    • Go to a python editor of your choice (I use juypter notebook) and try importing selenium. If it runs without error, your setup is successful.
  2. The Code:

    • Now copy down the following code:
from selenium import webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe" # Location of the webdriver file

driver = webdriver.Chrome(PATH)
driver.implicitly_wait(15) 
driver.get('https://web.whatsapp.com')
driver.find_element_by_css_selector("span[title='" + input("Enter name to spam: ") + "']").click()
inputString = input("Enter message to send: ")
while(True):
    driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]').send_keys(inputString)
    driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[3]/button').click()
Enter fullscreen mode Exit fullscreen mode

IMPORTANT NOTE : Please change the PATH to where you have saved the .exe file.

  1. The Final Outcome:
    • Using your phone scan the QR code for WhatsApp web and then enter the name and the message you want to spam.

Spammer in Action:

  • Copy and paste the code from above into your editor ( Preferably Juypter Notebook).

  • Run the code. You should be able to see something like the image below. You will also see that a new WhatsApp window opens up.

image

  • In the 'Enter the name to spam' Section', add the name of the contact or group you wish to spam.

  • In the 'Enter the message to spam', enter the string you wish to send.
    image

  • After you hit enter, check the Whatsapp window, you will see an infinite number of messages being sent to the group/contact.

  • To stop hit Ctrl + C or click on the stop button if you're on Juypter Notebook.

Conclusion:

The spammer works just as intended, and is extremely fast. It also provides a good eye-opener into the world of automation.

Commonly Faced Errors:

  • Sometimes, when importing selenium, you may get an import error. Check where selenium is installed and figure out where if the selenium installation and python path match. image

Happy Coding!

Discussion (0)

pic
Editor guide