Professional Documents
Culture Documents
Code Pal Result
Code Pal Result
This function uses the Selenium library to automate the process of sending
messages
on WhatsApp Web. It opens a Chrome browser, navigates to WhatsApp Web, searches
for
the specified contact, and sends the messages with the specified interval
between them.
Parameters:
- contact_name (str): The name of the contact to send the messages to.
- messages (list): A list of strings representing the messages to be sent.
- interval (int): The time interval (in seconds) between sending each message.
Raises:
- ValueError: If the 'messages' parameter is empty or if the 'interval'
parameter is less than or equal to zero.
Returns:
None
"""
try:
# Opening WhatsApp Web
driver.get("https://web.whatsapp.com")
# Waiting for the specified interval before sending the next message
time.sleep(interval)
finally:
# Closing the browser window
driver.quit()
# Sending three messages to the contact named "John Doe" with a 2-second interval
between each message
contact = "John Doe"
messages = ["Hello!", "How are you?", "This is an ultimate message!"]
interval = 2
try:
send_ultimate_messages(contact, messages, interval)
print("Messages sent successfully!")
except ValueError as e:
print(f"Error while sending messages: {e}")