Advertisement
severusDude

Python3 + selenium Whatsapp message automation updated

Jun 4th, 2020
1,390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. import time
  2.  
  3. from selenium import webdriver
  4. from selenium.webdriver.chrome.options import Options
  5. from selenium.webdriver.common.by import By
  6. from selenium.webdriver.common.keys import Keys
  7. from selenium.webdriver.support.ui import Select, WebDriverWait
  8.  
  9.  
  10. contact = "John"
  11. text = "Hi John, this is automated message"
  12. driver = webdriver.Chrome()
  13. driver.get("https://web.whatsapp.com")
  14. print("Scan QR Code, And then Enter")
  15. input()
  16. print("Logged In")
  17. inp_xpath_search = '//*[@id="side"]/div[1]/div/label/div/div[2]'
  18. input_box_search = WebDriverWait(driver, 50).until(
  19.     lambda driver: driver.find_element_by_xpath(inp_xpath_search))
  20. input_box_search.click()
  21. time.sleep(2)
  22. input_box_search.send_keys(contact)
  23. time.sleep(2)
  24. selected_contact = driver.find_element_by_xpath("//span[@title='"+contact+"']")
  25. selected_contact.click()
  26. inp_xpath = '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]'
  27. input_box = driver.find_element_by_xpath(inp_xpath)
  28. time.sleep(2)
  29. input_box.send_keys(text + Keys.ENTER)
  30. time.sleep(2)
  31. driver.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement