From eaa9011789d84a18754b72999c4c727778d37490 Mon Sep 17 00:00:00 2001 From: Shivam Pande Date: Fri, 21 Oct 2022 19:39:10 +0530 Subject: [PATCH] whatsapp automater with selenium python --- Python/Whatsapp_automator/Readme.txt | 7 ++++ .../Whatsapp_automator/whatsapp_automator.py | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 Python/Whatsapp_automator/Readme.txt create mode 100644 Python/Whatsapp_automator/whatsapp_automator.py diff --git a/Python/Whatsapp_automator/Readme.txt b/Python/Whatsapp_automator/Readme.txt new file mode 100644 index 00000000..6aae95cc --- /dev/null +++ b/Python/Whatsapp_automator/Readme.txt @@ -0,0 +1,7 @@ +Python code to automate whatsapp messages using selenium + +Needed imports: +- selenium +- time + +PS: Install the chrome drive for this to work and Xpath mai change from browser to browser so reconfirm them before using. \ No newline at end of file diff --git a/Python/Whatsapp_automator/whatsapp_automator.py b/Python/Whatsapp_automator/whatsapp_automator.py new file mode 100644 index 00000000..a287f1f6 --- /dev/null +++ b/Python/Whatsapp_automator/whatsapp_automator.py @@ -0,0 +1,40 @@ +from selenium import webdriver +import time + +#using the chrome web driver +driver = webdriver.Chrome("C:/Program Files (x86)/chromedriver.exe") + +#opening a new window +driver.get("https://web.whatsapp.com") + +#this is so that code wahts for the user to scan thw qr code to link the web whatsapp +print("Scan QR Code, And then Enter") +input() +print("Logged In") + +driver.maximize_window() + +#Searching for the person/number to send message to +text_area = driver.find_element( + by="xpath", value="//*[@id='side']/div[1]/div/div/div[2]/div/div[2]") +text_area.clear() +text_area.send_keys("6399149449") + +#Clicking on the result of the search that appears +chat_name = driver.find_element( + by='xpath', value="//*[@id='pane-side']/div[1]/div/div/div[1]/div/div/div") +chat_name.click() + + +message = "Hi.. I am a simple python script.." + +#finding the message bar and writing message to it +driver.find_element( + by='xpath', value='//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]').send_keys(message) + +#Finding the send button and clicking it +driver.find_element( + by='xpath', value='//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2]/button/span').click() + +#closing the window +driver.close()