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
#2
where is your keys class? what did you define there?
see docs
Reply
#3
(Jan-16-2024, 11:12 AM)Larz60+ Wrote: where is your keys class? what did you define there?
see docs

@Larz60
Honestly Python is a totally new ground for me. As I mentioned, I downloaded the code and using it.
Totally novice...

no idea what keys class is?
Please help
Reply
#4
This is what I find using inspect element on send icon

<div class="_2xy_p _3XKXx"><button data-tab="11" aria-label="Send" class="tvf2evcx oq44ahr5 lb5m6g5c svlsagor p2rjqpw5 epia9gcq"><span data-icon="send" class=""><svg viewBox="0 0 24 24" height="24" width="24" preserveAspectRatio="xMidYMid meet" class="" version="1.1" x="0px" y="0px" enable-background="new 0 0 24 24"><title>send</title><path fill="currentColor" d="M1.101,21.757L23.8,12.028L1.101,2.3l0.011,7.912l13.623,1.816L1.112,13.845 L1.101,21.757z"></path></svg></span></button></div>

This is XPath

//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2]

This is full XPath

/html/body/div[1]/div/div[2]/div[4]/div/footer/div[1]/div/span[2]/div/div[2]/div[2]

Hope it is of some use to you to help me out
Reply
#5
If the keys are not working and as you have said you have downloaded the codes online I think you should find some new keys for this.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Search box python selenium sendkeys dorabajji 0 1,499 Mar-10-2020, 09:41 AM
Last Post: dorabajji
  Trying to use win32 Sendkeys to log into database overnight statiCat 0 4,191 Apr-28-2018, 03:59 PM
Last Post: statiCat
  How to specify a Unicode character with Autokey keyboard.sendkeys()? ineuw 5 5,961 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