-
Notifications
You must be signed in to change notification settings - Fork 66
/
script.py
55 lines (44 loc) · 1.78 KB
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Program to send bulk customized message through WhatsApp web application
# Author @inforkgodara
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException
import pandas
import time
# Load the chrome driver
driver = webdriver.Chrome()
count = 0
# Open WhatsApp URL in chrome browser
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 20)
# Read data from excel
excel_data = pandas.read_excel('Customer bulk email data.xlsx', sheet_name='Customers')
# Iterate excel rows till to finish
for column in excel_data['Name'].tolist():
# Assign customized message
message = excel_data['Message'][0]
# Locate search box through x_path
search_box = '//*[@id="side"]/div[1]/div/label/div/div[2]'
person_title = wait.until(lambda driver:driver.find_element_by_xpath(search_box))
# Clear search box if any contact number is written in it
person_title.clear()
# Send contact number in search box
person_title.send_keys(str(excel_data['Contact'][count]))
count = count + 1
# Wait for 2 seconds to search contact number
time.sleep(2)
try:
# Load error message in case unavailability of contact number
element = driver.find_element_by_xpath('//*[@id="pane-side"]/div[1]/div/span')
except NoSuchElementException:
# Format the message from excel sheet
message = message.replace('{customer_name}', column)
person_title.send_keys(Keys.ENTER)
actions = ActionChains(driver)
actions.send_keys(message)
actions.send_keys(Keys.ENTER)
actions.perform()
# Close chrome browser
driver.quit()