|
| 1 | +# Selenium is required for automation |
| 2 | +# sleep is required to have some time for scanning |
| 3 | +from selenium import webdriver |
| 4 | +from selenium.common.exceptions import NoSuchElementException |
| 5 | +from selenium.webdriver.support.ui import WebDriverWait |
| 6 | +from selenium.webdriver.support import expected_conditions as EC |
| 7 | +from selenium.webdriver.common.keys import Keys |
| 8 | +from selenium.webdriver.common.by import By |
| 9 | +from time import sleep |
| 10 | + |
| 11 | + |
| 12 | +def whatsapp(to, message): |
| 13 | + person = [to] |
| 14 | + string = message |
| 15 | + chrome_driver_binary = "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe" |
| 16 | + # Selenium chromedriver path |
| 17 | + driver = webdriver.Chrome(chrome_driver_binary) |
| 18 | + driver.get("https://web.whatsapp.com/") |
| 19 | + sleep(15) |
| 20 | + # This will find the person we want to send the message to in the list |
| 21 | + for name in person: |
| 22 | + user = driver.find_element_by_xpath("//span[@title='{}']".format(name)) |
| 23 | + user.click() |
| 24 | + text_box = driver.find_element_by_xpath( |
| 25 | + '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]') |
| 26 | + try: |
| 27 | + text_box.send_keys(string) |
| 28 | + sendbutton = driver.find_elements_by_xpath( |
| 29 | + '//*[@id="main"]/footer/div[1]/div[3]/button')[0] |
| 30 | + sendbutton.click() |
| 31 | + sleep(10) |
| 32 | + print('Message Sent!!') |
| 33 | + except: |
| 34 | + print('Error occured....') |
| 35 | + |
| 36 | + |
| 37 | +if __name__ == "__main__": |
| 38 | + to = input('Who do you want to send a message to? Enter the name: ') |
| 39 | + content = input("What message to you want to send? Enter the message: ") |
| 40 | + whatsapp(to, content) |
0 commit comments