简体   繁体   中英

raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

I'm trying to use WhatsApp via python following the below code, but I'm receiving the following error: raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

Is there something wrong with the code, or something that I'm missing here? Could some one please help me here in fixing this and how do I send auto-reply using python scrips in WhatsApp.

Thank you for the help.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

# Replace below path with the absolute path
# to chromedriver in your computer
driver = webdriver.Chrome('/home/saket/Downloads/chromedriver')

driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)

# Replace 'Friend's Name' with the name of your friend 
# or the name of a group 
target = '"Friend\'s Name"'

# Replace the below string with your own message
string = "Message sent using Python!!!"

x_arg = '//span[contains(@title,' + target + ')]'
group_title = wait.until(EC.presence_of_element_located((
    By.XPATH, x_arg)))
group_title.click()
inp_xpath = '//div[@class="input"][@dir="auto"][@data-tab="1"]'
input_box = wait.until(EC.presence_of_element_located((
    By.XPATH, inp_xpath)))
for i in range(100):
    input_box.send_keys(string + Keys.ENTER)
    time.sleep(1)

You can handle that exception,

from selenium.common.exceptions import TimeoutException

try:
    driver.get("https://web.whatsapp.com/")
except TimeoutException:
    # You can write retry code here

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM