Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from selenium import webdriver
- from selenium.webdriver.chrome.options import Options
- from selenium.webdriver.common.by import By
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support.ui import Select, WebDriverWait
- contact = "John"
- text = "Hi John, this is automated message"
- driver = webdriver.Chrome()
- driver.get("https://web.whatsapp.com")
- print("Scan QR Code, And then Enter")
- input()
- print("Logged In")
- inp_xpath_search = '//*[@id="side"]/div[1]/div/label/div/div[2]'
- input_box_search = WebDriverWait(driver, 50).until(
- lambda driver: driver.find_element_by_xpath(inp_xpath_search))
- input_box_search.click()
- time.sleep(2)
- input_box_search.send_keys(contact)
- time.sleep(2)
- selected_contact = driver.find_element_by_xpath("//span[@title='"+contact+"']")
- selected_contact.click()
- inp_xpath = '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]'
- input_box = driver.find_element_by_xpath(inp_xpath)
- time.sleep(2)
- input_box.send_keys(text + Keys.ENTER)
- time.sleep(2)
- driver.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement