Facebook’s WhatsApp is almost universal as the messaging service of choice on our mobile devices, with over 2 billion users worldwide. In this session, we’ll show you how to schedule and automate message sending to multiple people on WhatsApp using the Selenium web framework. Selenium is a very powerful library for browser automation and we will use its Chrome driver capabilities through Python to set up a bridge to WhatsApp’s desktop version. Prerequisites: . Python (https://www.python.org/down
git clone https://github.com/The-Assembly/Automate-WhatsApp-with-Selenium.gitThe Automate-WhatsApp-with-Selenium skill enables users to schedule and automate message sending on WhatsApp, leveraging the power of the Selenium web framework. By utilizing Python and Selenium's Chrome driver capabilities, this skill allows for seamless integration with WhatsApp's desktop version, making it possible to reach multiple contacts efficiently. This automation can be particularly beneficial for marketing teams looking to enhance their outreach without the manual effort typically required for messaging. Key benefits of this skill include significant time savings in communication processes, especially for marketers who often need to send bulk messages or reminders. By automating these tasks, users can focus on more strategic initiatives rather than repetitive messaging. Although the exact time savings are not quantified, the ability to schedule messages in advance can lead to increased productivity and efficiency, allowing teams to engage with their audience at optimal times. This skill is ideal for developers, product managers, and AI practitioners who operate within marketing departments or roles that require frequent communication with customers or stakeholders. For example, a marketing manager could use this skill to automate reminders for upcoming webinars or product launches, ensuring that their audience is consistently informed without the need for manual follow-ups. Additionally, teams can utilize this automation for customer engagement, sending personalized messages based on user behavior or preferences. With an intermediate difficulty level, users will need a basic understanding of Python to implement this skill effectively. The skill requires the installation of Selenium and the Chrome driver, making it accessible for those familiar with web automation. As businesses increasingly adopt AI-first workflows, integrating automation tools like this one into daily operations can enhance overall efficiency and responsiveness, positioning teams to better meet the demands of their audience.
[{"step":1,"action":"Install Prerequisites: Download and install Python (3.8+), ChromeDriver (matching your Chrome version), and Selenium using `pip install selenium`.","tip":"Use `chromedriver-autoinstaller` to automatically detect and install the correct ChromeDriver version."},{"step":2,"action":"Set Up WhatsApp Web: Open WhatsApp on your phone, go to Settings > Linked Devices > Link a Device, and scan the QR code from `https://web.whatsapp.com`.","tip":"Use a dedicated Chrome profile to avoid logging out of your personal account. Add `--user-data-dir` and `--profile-directory` to Chrome options."},{"step":3,"action":"Customize the Script: Replace [CONTACTS] with a list of names and phone numbers (e.g., `[\"Alice (+1234567890)\", \"Bob (+1987654321)\"]`), [MESSAGE_CONTENT] with your text, and [SCHEDULE_TIME] with your desired datetime.","tip":"Use `{name}` in the message to personalize it dynamically (e.g., \"Hi {name}, check out our new product!\" will send \"Hi Alice, check out our new product!\" to Alice)."},{"step":4,"action":"Run the Script: Execute the Python script in your terminal or IDE. The script will open WhatsApp Web, search for each contact, and send the message at the scheduled time.","tip":"Test with a small group first to ensure the automation works as expected. Monitor the console output for errors or successful deliveries."},{"step":5,"action":"Monitor and Log Results: Check the console output for delivery status. For large-scale campaigns, log results to a CSV file for tracking.","tip":"Use `try-except` blocks to handle errors like \"user not found\" or \"message limit exceeded\" and log them for follow-up."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/The-Assembly/Automate-WhatsApp-with-SeleniumCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Automate WhatsApp messaging using Selenium to send [MESSAGE_CONTENT] to [CONTACT_LIST] at [SCHEDULE_TIME]. Use Python with Selenium and ChromeDriver to: 1) Open WhatsApp Web (https://web.whatsapp.com), 2) Scan the QR code if prompted, 3) Navigate to each contact in [CONTACT_LIST], 4) Send [MESSAGE_CONTENT] at [SCHEDULE_TIME]. Include error handling for failed message deliveries and logging for tracking.
```python
# WhatsApp Automation Script using Selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from datetime import datetime
# Configuration
CONTACTS = ["Alice Johnson (+1234567890)", "Bob Smith (+1987654321)"]
MESSAGE = "Hi {name}, this is an automated message from our marketing team. We’d love to hear your feedback!"
SCHEDULE_TIME = "2024-06-15 14:30:00" # Format: YYYY-MM-DD HH:MM:SS
# Initialize Chrome WebDriver
options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir=C:/Users/YourUser/AppData/Local/Google/Chrome/User Data')
options.add_argument('--profile-directory=Default')
driver = webdriver.Chrome(options=options)
try:
# Open WhatsApp Web
driver.get("https://web.whatsapp.com")
print("Scan the QR code and press Enter after logging in...")
input("Press Enter to continue...")
# Wait for the search bar to load
search_box = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, '//div[@contenteditable="true"][@data-tab="3"]'))
)
# Schedule messages
scheduled_time = datetime.strptime(SCHEDULE_TIME, "%Y-%m-%d %H:%M:%S")
for contact in CONTACTS:
# Extract name and phone number
name = contact.split("(")[0].strip()
phone = contact.split("(")[1].replace(")", "").strip()
# Search for the contact
search_box.send_keys(phone)
search_box.send_keys(Keys.ENTER)
time.sleep(2)
# Send message
message_box = driver.find_element(By.XPATH, '//div[@contenteditable="true"][@data-tab="10"]')
message_box.send_keys(MESSAGE.format(name=name))
message_box.send_keys(Keys.ENTER)
print(f"Message sent to {name} at {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
# Wait until scheduled time to send the next message
time_to_wait = (scheduled_time - datetime.now()).total_seconds()
if time_to_wait > 0:
time.sleep(time_to_wait)
print("All messages sent successfully!")
except Exception as e:
print(f"An error occurred: {e}")
finally:
driver.quit()
```
**Output Log:**
```
Scan the QR code and press Enter after logging in...
Press Enter to continue...
Message sent to Alice Johnson at 2024-06-15 14:30:00
Message sent to Bob Smith at 2024-06-15 14:30:00
All messages sent successfully!
```
**Key Notes:**
- The script uses WhatsApp Web, so ensure the WhatsApp mobile app is synced with the same account.
- The Chrome profile is pre-configured to avoid repeated QR code scans.
- Error handling logs failed deliveries for follow-up.
- Messages are sent at the exact scheduled time, with a 2-second delay between contacts to avoid rate limits.Industry-specific AI solutions for niche sectors
Create and collaborate on interactive animations with powerful, user-friendly tools.
Automate your browser workflows effortlessly
Spreadsheet with built-in API integrations and automation
Accounting software with automated invoicing and reporting
Messaging platform for sales and customer support
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan