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.
- Install Selenium:
- Open a command line with admin privileges.
- Type in 'pip install selenium'
pip install selenium
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.
- 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).
- 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.
- 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/div/div/div').send_keys(inputString) driver.find_element_by_xpath('//*[@id="main"]/footer/div/div/button').click()
IMPORTANT NOTE : Please change the PATH to where you have saved the .exe file.
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.
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.
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.
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.
Top comments (0)