简体   繁体   English

selenium.common.exceptions.TimeoutException 错误使用 WebDriverWait 通过 Selenium 和 Python

[英]selenium.common.exceptions.TimeoutException error using WebDriverWait with expected_conditions through Selenium and Python

Traceback (most recent call last):
  File "Inventorytest.py", line 88, in <module>
    j.go_to_application()
  File "Inventorytest.py", line 65, in go_to_application
    EC.element_to_be_clickable((By.ID, 'FavoriteApp_ITEM'))
  File "/home/naroladev/Mercury_Back-End/mercuryenv/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

I got above exception with EC2 server instance.我遇到了 EC2 服务器实例的上述异常。 My script works absolutely fine with Ubuntu and Mac os with any version of firefox and geckodriver on local system.我的脚本在 Ubuntu 和 Mac os 与任何版本的 firefox 和 geckodriver 在本地系统上都可以正常工作。 But got above error with EC2 ubuntu 18.04.01 version, in this I have also tried upgrade and downgrade firefox and geckodriver versions but still not work.但是 EC2 ubuntu 18.04.01 版本出现上述错误,在此我也尝试升级和降级 firefox 和 geckodriver 版本,但仍然无法正常工作。 Can anyone help me out with suggestion and solutions.任何人都可以帮助我提出建议和解决方案。

This error message...此错误消息...

Traceback (most recent call last):
  File "Inventorytest.py", line 88, in <module>
    j.go_to_application()
  File "Inventorytest.py", line 65, in go_to_application
    EC.element_to_be_clickable((By.ID, 'FavoriteApp_ITEM'))
  File "/home/naroladev/Mercury_Back-End/mercuryenv/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

...implies that the WebDriver variant was unable to locate the desired WebElement within the timeframe for which the WebDriverWait was constructed. ...意味着WebDriver变体无法在构建WebDriverWait的时间范围内找到所需的WebElement


WebDriverWait WebDriverWait

The WebDriverWait constructor takes a WebDriver instance as an argument and timeout in seconds. WebDriverWait构造函数将WebDriver实例作为参数并以秒为单位超时。

Hence, irrespective of usage of either of the expected_conditions , WebDriverWait on failure will result in TimeoutException .因此,无论使用任何一个expected_conditionsWebDriverWait失败都会导致TimeoutException


This usecase这个用例

In this usecase, the line:在此用例中,该行:

EC.element_to_be_clickable((By.ID, 'FavoriteApp_ITEM'))

was unable to identify the desired element within the desired time frame hence you faced TimeoutException .无法在所需的时间范围内识别所需的元素,因此您面临TimeoutException

However, from TimeoutException it will be tough to dig out the actual result of the failure.但是,从TimeoutException中很难挖掘出失败的实际结果。


Solution解决方案

As a solution to know about the exact cause of the failure, you need to remove the WebDriverWait and replace the line of code with either:作为了解失败确切原因的解决方案,您需要删除WebDriverWait并将代码行替换为:

  • find_element_by_class_name(name)
  • find_element_by_css_selector(css_selector)
  • find_element_by_id(id)
  • find_element_by_link_text(link_text)
  • find_element_by_name(name)
  • find_element_by_partial_link_text(partial_link_text)
  • find_element_by_tag_name(tag_name)
  • find_element_by_xpath(xpath)

If required you can slow down the search inducing waits through time.sleep(secs) while debugging.如果需要,您可以在调试时通过time.sleep(secs)减慢搜索诱导等待。


References参考

You can find a couple of relevant discussions in:您可以在以下位置找到一些相关的讨论:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium.common.exceptions.TimeoutException 在使用 Selenium Python 中的 expected_conditionspresence_of_element_located 单击按钮时 - selenium.common.exceptions.TimeoutException while clicking on a button using expected_conditions presence_of_element_located in Selenium Python Python Selenium _ 错误:selenium.common.exceptions.TimeoutException _ 与 WebDriverWait - Python Selenium _ Error: selenium.common.exceptions.TimeoutException _ with WebDriverWait Python Selenium _ 错误:selenium.common.exceptions.TimeoutException - Python Selenium _ Error: selenium.common.exceptions.TimeoutException selenium.common.exceptions.TimeoutException 使用 Selenium 和 Python 定位一个元素 - selenium.common.exceptions.TimeoutException locating an element using Selenium with Python 错误:selenium.common.exceptions.TimeoutException:消息: - error: selenium.common.exceptions.TimeoutException: Message: selenium.common.exceptions.TimeoutException:使用 Selenium ZA7F1735426B93273 将文本发送到 iframe 中的用户名字段的消息错误 - selenium.common.exceptions.TimeoutException: Message error sending text to username field within iframe using Selenium Python 通过硒和python 3使用element_to_be_clickable方法时,Expected_Conditions返回TimeoutException - Expected_Conditions returns TimeoutException while using element_to_be_clickable method through selenium & python 3 引发TimeoutException(消息,屏幕,堆栈跟踪)selenium.common.exceptions.TimeoutException:消息:使用Selenium Python - raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: using Selenium Python python和Selenium不一致的selenium.common.exceptions.TimeoutException - Inconsistent selenium.common.exceptions.TimeoutException with Python and Selenium selenium.common.exceptions.TimeoutException:当我尝试使用python进行按钮单击时,将出现此错误 - selenium.common.exceptions.TimeoutException: this error will getting when I'm trying to button click using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM