In this article, we will guide you to create an Automated bot or Whatsapp Spam Bot Using Python Selenium. We will use tkinter and selenium for creating our whatsapp spam bot.
SELENIUM:
“Selenium automates browsers. That’s it! What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes but is certainly not limited to just that” — from selenium website.
We can use selenium in many languages like Java and Python. Here, we will use selenium to Automate and repeat WhatsApp messages Using Python.
To know more about Selenium installation and setup check both the links below:
TKINTER:
What is Tkinter? it is used library provides Python users with a simple way to create GUI elements using the widgets found in the Tk toolkit. Tk widgets can be used to construct buttons, menus, data fields, etc. in a Python application.
“Simply Tkinter pops windows which make the code user friendly”.
SETTING ENVIRONMENT:
While installing python make sure the check boxes shown above are ticked. If not while reinstalling go to advanced installation settings and tick the check box. It will be useful if you are dealing with python IDLE. Its advisable to use PyCharm.
If you are dealing with pycharm IDE. You may frequently encounter a error while dealing with tkinter projects on PyCharm . To rectify the error it follow the steps below. If you are perfect with your environment you can skip this step and check the program.
As shown above first open PyCharm IDE > Settings > Project settings > Project interpreter > Add packages > Install Future Package.
PROGRAM:
First import all the necessary packages
Coming to Tkinter code:
Creating tkinter window and adding title and header description to it.
INPUT:
OUTPUT:
Now lets add fields to the tkinter window. we can also use input variable and selenium code instead of tkinter window.But using tkinter makes it userfriendly.
INPUT:
OUTPUT:
Coming to selenium code:
Just locating the Xpath of contact name / contact number makes the code much easy.
selenium code makes to pop up the webwhatsapp on your browser scan the qr code and enter whats app.
INPUT:
OUTPUT:
Wait for a while and see the magic. check the complete code below hope you like this stay tuned for more 🙂 .
import time import tkinter as tk from tkinter import * from selenium import webdriver from selenium.webdriver.common.keys import Keys def startBombing(): victim=str(name.get()) msg=str(message.get()) num=msgCount.get() driver=webdriver.Chrome('enter you path here example of a path : [C:/Users/91728/Desktop/pythonProject/chromedriver.exe] ') driver.get("https://web.whatsapp.com/") time.sleep(15) user=driver.find_element_by_xpath('//span[@title = "'+victim+'"]') user.click() msg_box=driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]') for i in range(num): msg_box.send_keys(msg) msg_box.send_keys(Keys.ENTER) #GUI root=tk.Tk() root.title("Whatsapp Bombing") root.geometry("500x500") root.resizable(height=False,width=False) headingLabel=Label(root,text="Wait for 15 - 30 sec to start BOOM!",font=('Helvetics',12,'bold')) headingLabel.place(relx=.5,y=15,anchor='center') # victim name label Label(root,text="Enter Name/No.").place(x=120,y=80) name=StringVar() nameBox=Entry(root,textvariable=name).place(x=220,y=80) # Msg label Label(root,text="Enter Message").place(x=120,y=150) message=StringVar() msgBox=Entry(root,textvariable=message).place(x=220,y=150) Label(root,text="No Of Message").place(x=120,y=220) msgCount=IntVar() countBox=Entry(root,textvariable=msgCount).place(x=220,y=220) tk.Button(root,text="Start Bombing",command=startBombing).place(relx=.5,y=300,anchor="center") root.mainloop()
Feel free to comment below. Thank you for spending your valuable time on this.
Keep learning
Also Read:
YouTube Video Downloader Application Using Python
Python Web scraping using Python Selenium
Automate Facebook Login Using Python Selenium
Shutdown Computer with Voice in Python
Jarvis and Google Assistant || Voice Assistant Using Python
Crack Any Password Using Python
Get WiFi Passwords With Python