Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SendKeys not working
#1
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.

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()
Reply


Messages In This Thread
SendKeys not working - by SanjayGMusafir - Jan-16-2024, 10:12 AM
RE: SendKeys not working - by Larz60+ - Jan-16-2024, 11:12 AM
RE: SendKeys not working - by SanjayGMusafir - Jan-16-2024, 11:20 AM
RE: SendKeys not working - by SanjayGMusafir - Jan-16-2024, 11:30 AM
RE: SendKeys not working - by EdwardMatthew - Jan-16-2024, 12:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search box python selenium sendkeys dorabajji 0 1,515 Mar-10-2020, 09:41 AM
Last Post: dorabajji
  Trying to use win32 Sendkeys to log into database overnight statiCat 0 4,239 Apr-28-2018, 03:59 PM
Last Post: statiCat
  How to specify a Unicode character with Autokey keyboard.sendkeys()? ineuw 5 5,989 Nov-04-2017, 08:43 PM
Last Post: ineuw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020