Facebook
From Rajesh, 5 Months ago, written in Plain Text.
This paste is a reply to Untitled from Rajesh - view diff
Embed
Download Paste or View Raw
Hits: 213
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.service import Service
  3. from webdriver_manager.chrome import ChromeDriverManager
  4. from selenium.webdriver.common.action_chains import ActionChains
  5. from selenium.webdriver.common.keys import Keys
  6. from selenium.webdriver.common.by import By
  7. from urllib.parse import quote
  8. import time
  9.  
  10. with open('msg2.txt','r') as file:
  11.     msg = file.read()
  12.  
  13. msg=quote(msg)
  14.  
  15. number = []
  16. with open('numbers.txt','r') as file:
  17.     for num in file.readlines():
  18.         number.append(num.rstrip())
  19.  
  20. driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
  21.  
  22. link = 'https://web.whatsapp.com/'
  23. driver.get(link)
  24. time.sleep(40)
  25.  
  26.  
  27.  
  28. for num in number:
  29.     link2 = f'https://web.whatsapp.com/send/?phone=91{num}&text;={msg}'
  30.     driver.get(link2)
  31.     print("link"+link2)
  32.     time.sleep(15)
  33.     action = ActionChains(driver)
  34.  
  35.     time.sleep(100)
  36.    
  37.  
  38.     attachment_btn = driver.find_element(By.XPATH,'//*[@id="main"]/footer/div[1]/div/span[2]/div/div[1]/div[2]/div/div')
  39.     attachment_btn.click()
  40.  
  41.     time.sleep(20)
  42.  
  43.     image_btn = driver.find_element(By.XPATH,'//*[@id="main"]/footer/div[1]/div/span[2]/div/div[1]/div[2]/div/span/div/ul/div/div[2]/li/div')
  44.     #image_btn = driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div[5]/div/footer/div[1]/div/span[2]/div/div[1]/div[2]/div/span/div/ul/div/div[2]/li/div/span")
  45.    
  46.     time.sleep(20)
  47.  
  48.     image_btn.send_keys('E:\FITECH\Contacts\Whatsapp send automation\spring-boot-microservices-online-training.jpeg')  # Replace with your image file path
  49.    
  50.     action.send_keys(Keys.ENTER)
  51.     action.perform()
  52.     time.sleep(10)
  53.  
  54. time.sleep(2000)
  55.