添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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)
                I see only one element with mentioned attributes (class="input", dir="auto", data-tab="1") and it's not div, but input... Could you try inp_xpath = '//input[@class="input"][@dir="auto"][@data-tab="1"]'? Also note that compound class name is "input input-search", but not just "input", so you should use [contains(@class, "input")] or [@class="input-search"]
– Andersson
                May 27, 2017 at 8:20
                here is the output after updating as mentioned above:         raise exception_class(message, screen, stacktrace)         selenium.common.exceptions.ElementNotVisibleException: Message: element not visible       (Session info: chrome=58.0.3029.110)       (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platf
– Shri
                May 27, 2017 at 8:28
                Traceback (most recent call last):   File "whatsapp.py", line 25, in <module>     group_title.click()   File "C:\Users\Desktop\ML\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\selenium\webdriver\remote\webelement.py", line 77, in click
– Shri
                May 27, 2017 at 9:24
                self._execute(Command.CLICK_ELEMENT)   File "C:\Users\Desktop\ML\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\selenium\webdriver\remote\webelement.py", line 493, in _execute     return self._parent.execute(command, params)   File "C:\Users\Desktop\ML\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in execute
– Shri
                May 27, 2017 at 9:24
    driver.get("https://web.whatsapp.com/")
except TimeoutException:
    # You can write retry code here

I hope this helps.

File "whatsapp.py", line 13, in <module> browser.get(url) NameError: name 'browser' is not defined During handling of the above exception, another exception occurred: Traceback (most recent call last): File "whatsapp.py", line 14, in <module> except TimeoutException: NameError: name 'TimeoutException' is not defined – Shri May 27, 2017 at 8:34 Above is what i got after adding " try: browser.get(url) except TimeoutException: # You can write retry code here" – Shri May 27, 2017 at 8:35 Please check the updated answer. If you use separate function to connect to the sire using driver.get(), then you can make that function recursive in TimeoutException. – Akash Wankhede May 27, 2017 at 16:43 here is another error: File "whatsapp.py", line 32, in <module> input_box.send_keys(string + Keys.ENTER) NameError: name 'input_box' is not defined – Shri May 27, 2017 at 17:18

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.