`from selenium import webdriver from selenium.common.exceptions import NoSuchElementException import time import os
Replace with the path to your chromedriver executable
chromedriver_path = os.path.join(os.getcwd(), 'chromedriver_win32', 'chromedriver.exe')
Replace with the path to the files you want to send
files_to_send = [os.path.join(os.getcwd(), 'files', 'In action presentation.pdf'), os.path.join(os.getcwd(), 'files', 'WhatsApp Audio 2023-03-08 at 12.15.51 AM.ogg')]
Replace with your message text
message = "Hello, this is a test message."
List of phone numbers
phone_numbers = ['+1234567890']
Initialize the Chrome webdriver
driver = webdriver.Chrome(chromedriver_path)
Open WhatsApp Web
driver.get('https://web.whatsapp.com/')
Wait for the user to scan the QR code
input('Scan the QR code and press Enter to continue...')
Loop through the list of phone numbers
for phone_number in phone_numbers:
# Navigate to the chat with the phone number
driver.get(f'https://web.whatsapp.com/send?phone={phone_number}')
try:
# Wait for the chat window to load
chat_window = driver.find_element_by_xpath('//div[@class="_3uMse"]')
time.sleep(5)
# Click on the attachment button
attachment_button = driver.find_element_by_xpath('//div[@title="Attach"]')
attachment_button.click()
# Click on the "Document" option
document_button = driver.find_element_by_xpath('//input[@accept="*"]')
document_button.send_keys('\n'.join(files_to_send))
# Wait for the files to upload
time.sleep(10)
# Type the message text
message_box = driver.find_element_by_xpath('//div[contains(@class, "input")]')
message_box.send_keys(message)
# Send the message
send_button = driver.find_element_by_xpath('//span[@data-icon="send"]')
send_button.click()
except NoSuchElementException:
print(f'Unable to send message to {phone_number}. Chat window not found.')
Close the webdriver
driver.quit() `
when i run the code whatsapp web open then I scan the code but then nothing else happens and the terminal give me this : the output from the terminal I want this script to send some files and a text message to list of numbers in whatsapp web and I just face this error but I cant find any syntax error or logical , I dont understand what is wrong with the usb port , I tried to plug in a USB it it works just fine , unfortunate I dont have another device to try the script on I hope some one can help me with this and thanks in advance , your fellow beginner new learner programmer :)