forked from lucaslattari/Whatsapp-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendMessage.py
44 lines (40 loc) · 1.79 KB
/
sendMessage.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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from utils import *
import itertools
import time
def sendMultipleMessages(browser, arrayContactName, arrayMessage):
for (contact, message) in zip(arrayContactName, arrayMessage):
searchForContact(browser, contact)
sendSingleMessage(browser, contact, message)
deleteInputText(browser)
def deleteInputText(browser):
searchInputText = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div/div[3]/div/div[1]/div/label/div/div[2]')))
searchInputText.click()
print("Cliquei no campo de busca de contato.")
time.sleep(3)
searchInputText.send_keys(Keys.CONTROL, 'a')
print("Selecionei o nome anterior.")
time.sleep(3)
searchInputText.send_keys(Keys.BACKSPACE)
print("Apaguei o nome do contato anterior da busca.")
time.sleep(5)
def searchForContact(browser, contactName):
searchInputText = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div/div[3]/div/div[1]/div/label/div/div[2]')))
searchInputText.click()
print("Cliquei no campo de busca de contato.")
time.sleep(3)
searchInputText.send_keys(contactName)
print("Digitei o nome do contato: " + contactName + ".")
time.sleep(3)
searchInputText.send_keys(Keys.ENTER)
print("Apertei ENTER.")
time.sleep(3)
def sendSingleMessage(browser, contactName, message):
messageInputText = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]')))
messageInputText.send_keys(message)
print("Escrevi a mensagem.")
time.sleep(3)
messageInputText.send_keys(Keys.ENTER)
print("Mensagem enviada!")
time.sleep(3)