Last active
January 8, 2023 15:46
-
-
Save stevedep/aa9469630b59e3a27ff8cd185275fb27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium.webdriver.firefox.options import Options | |
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.wait import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
import time | |
from datetime import datetime | |
def send_message(msg, t="s", group="testing"): | |
website = "https://web.whatsapp.com/" | |
options=Options() | |
options.add_argument('-profile') | |
options.add_argument('/home/odroid/Documents/PythonProfile') | |
driver = webdriver.Firefox(options=options, service_log_path='/home/odroid/geckodriver.log') | |
driver.implicitly_wait(400) | |
driver.get(website) | |
try: | |
searchbar = WebDriverWait(driver,40).until(EC.presence_of_element_located((By.XPATH,"//span[@title='"+group+"']"))) | |
except: | |
driver.save_screenshot('ss.png') | |
driver.quit() | |
print("fail") | |
group = driver.find_element(By.XPATH, "//span[@title='"+group+"']") | |
group.click() | |
txtbox = driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]') | |
time.sleep(4) | |
txtbox.click() | |
if t=="s": | |
time.sleep(4) | |
for element in msg: | |
txtbox.send_keys(element) | |
time.sleep(4) | |
btn = driver.find_element(By.CSS_SELECTOR, "Button[aria-label='Send']") | |
btn.click() | |
else: | |
for item in msg: | |
txtbox.click() | |
time.sleep(2) | |
for element in item: | |
txtbox.send_keys(element) | |
time.sleep(2) | |
btn = driver.find_element(By.CSS_SELECTOR, "Button[aria-label='Send']") | |
btn.click() | |
time.sleep(15) | |
driver.close() | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment