Jan-16-2024, 10:12 AM
(This post was last modified: Jan-16-2024, 10:12 AM by SanjayGMusafir.)
Hi Experts
I'm using a code that I downloaded from internet.
It is working fine until the message is composed but for some reason it does not send the message.
Thanks in advance
The entire code is as under just in case required -
I'm using a code that I downloaded from internet.
It is working fine until the message is composed but for some reason it does not send the message.
action = ActionChains(driver) action.send_keys(Keys.ENTER).perform() action.perform()Please help
Thanks in advance
The entire code is as under just in case required -
# Packages
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from Config import CHROME_FILE_PATH
import time
# Config
login_time = 15 # Time for login (in seconds)
new_msg_time = 5 # TTime for a new message (in seconds)
send_msg_time = 12 # Time for sending a message (in seconds)
country_code = 91 # Set your country code
# action_time = 2 # Set time for button click action
# image_path = 'Image.png' # Absolute path to you image
# Create driver
option = webdriver.ChromeOptions()
option.add_argument(CHROME_FILE_PATH)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=option)
# Encode Message Text
with open('message.txt', 'r',encoding='utf8') as file:
msg = file.read()
numbers = []
with open('numbers.txt', 'r') as file:
for n in file.readlines():
# num = n.rstrip()
numbers.append(n.rstrip())
# Defining default links
link1 = 'https://web.whatsapp.com'
link2 = f'https://web.whatsapp.com/send/?phone={n}&text={msg}'
# Open browser with default link
driver.get(link1)
time.sleep(login_time)
# Loop Through Numbers List
for n in numbers:
driver.get(link2)
time.sleep(new_msg_time)
# Start the action chain to write the message
action = ActionChains(driver)
action.send_keys(Keys.ENTER).perform()
action.perform()
time.sleep(send_msg_time)
# Quit the driver
driver.quit()
