SendKeys not working - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: SendKeys not working (/thread-41440.html) |
SendKeys not working - SanjayGMusafir - Jan-16-2024 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() RE: SendKeys not working - Larz60+ - Jan-16-2024 where is your keys class? what did you define there? see docs RE: SendKeys not working - SanjayGMusafir - Jan-16-2024 (Jan-16-2024, 11:12 AM)Larz60+ Wrote: where is your keys class? what did you define there? @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 RE: SendKeys not working - SanjayGMusafir - Jan-16-2024 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 RE: SendKeys not working - EdwardMatthew - Jan-16-2024 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. |