Advertisement
ayiemedia

Selenium WebDriver

Aug 12th, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | Source Code | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. import time
  4.  
  5. # Initialize WebDriver (Make sure the ChromeDriver path is correct)
  6. driver = webdriver.Chrome(executable_path='path/to/chromedriver')
  7.  
  8. # Open WhatsApp Web
  9. driver.get("https://web.whatsapp.com")
  10.  
  11. # Wait for the user to scan the QR code
  12. time.sleep(15)  # Adjust the sleep time based on your needs
  13.  
  14. # Function to send a message to a number
  15. def send_message(phone_number, message):
  16.     url = f"https://wa.me/{phone_number}?text={message}"
  17.     driver.get(url)
  18.    
  19.     # Wait for the page to load
  20.     time.sleep(5)
  21.    
  22.     # Locate the "Send" button and click it
  23.     send_button = driver.find_element_by_xpath("//button[@data-testid='compose-btn-send']")
  24.     send_button.click()
  25.  
  26. # List of phone numbers
  27. phone_numbers = ["1234567890", "0987654321"]  # Add numbers in international format
  28.  
  29. # Message to send
  30. message = "Hello, this is an automated message."
  31.  
  32. # Loop through the numbers and send the message
  33. for number in phone_numbers:
  34.     send_message(number, message)
  35.     time.sleep(5)  # Adjust the sleep time to allow for message sending
  36.  
  37. # Close the browser after sending messages
  38. driver.quit()
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement