-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsendMessage.py
More file actions
46 lines (38 loc) · 1.27 KB
/
sendMessage.py
File metadata and controls
46 lines (38 loc) · 1.27 KB
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
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
import random
driver = webdriver.Chrome('chromedriver.exe')
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 1000)
print("Waiting done...")
target = ' '
x_arg = '//span[@title="' + target + '"][@dir="auto"]'
friend = wait.until(EC.presence_of_element_located((
By.XPATH, x_arg)))
try:
driver.find_element_by_xpath(x_arg).click()
print("Found")
except NoSuchElementException:
print("Not found")
inp_xpath = '//div[@class="selectable-text"][@data-tab="1"]'
try:
driver.find_element_by_class_name("selectable-text")
print("Found")
except NoSuchElementException:
print("Not found")
n = 0
multiline_msg = ''' '''
lines = multiline_msg.split("\n")
for line in lines:
input_box = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
for letter in line:
time.sleep(random.uniform(0, 2))
input_box.send_keys(letter)
input_box.send_keys(Keys.RETURN)
n = n + 1
time.sleep(1)