![](/img/trans.png)
[英]TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
[英]raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
我正在嘗試按照以下代碼通過python使用WhatsApp,但收到以下錯誤: raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
跟蹤raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
代碼是否有問題,或者我在這里缺少什么? 有人可以幫我解決這個問題,以及如何在WhatsApp中使用python腳本發送自動回復。
感謝您的幫助。
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)
您可以處理該異常,
from selenium.common.exceptions import TimeoutException
try:
driver.get("https://web.whatsapp.com/")
except TimeoutException:
# You can write retry code here
我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.