问题描述
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:
我遇到了 EC2 服务器实例的上述异常.我的脚本在 Ubuntu 和 Mac os 上运行得非常好,在本地系统上使用任何版本的 firefox 和 geckodriver.但是在 EC2 ubuntu 18.04.01 版本上出现了上述错误,在此我也尝试升级和降级 firefox 和 geckodriver 版本,但仍然无法正常工作.任何人都可以帮助我提出建议和解决方案.
I got above exception with EC2 server instance. My script works absolutely fine with Ubuntu and Mac os with any version of firefox and geckodriver on local system. 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. Can anyone help me out with suggestion and solutions.
推荐答案
此错误信息...
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:
...暗示 WebDriver 变体无法找到所需的 WebElement 在 WebDriverWait 已构建.
...implies that the WebDriver variant was unable to locate the desired WebElement within the timeframe for which the WebDriverWait was constructed.
WebDriverWait 构造函数采用 WebDriver 实例作为参数并以秒为单位超时.
The WebDriverWait constructor takes a WebDriver instance as an argument and timeout in seconds.
因此,无论是否使用 expected_conditions, WebDriverWait 失败将导致 TimeoutException.
Hence, irrespective of usage of either of the expected_conditions, WebDriverWait on failure will result in TimeoutException.
在这个用例中,行:
EC.element_to_be_clickable((By.ID, 'FavoriteApp_ITEM'))
无法在所需的时间范围内识别所需的元素,因此您面临 TimeoutException.
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.
作为了解失败确切原因的解决方案,您需要删除 WebDriverWait 并将代码行替换为:
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:
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)
如果需要,您可以通过 time.sleep(secs)
调试时.
If required you can slow down the search inducing waits through time.sleep(secs)
while debugging.
您可以在以下位置找到一些相关讨论:
You can find a couple of relevant discussions in:
- selenium.common.exceptions通过 expected_conditions 对元素调用 .click() 时发生 .TimeoutException
- ExpectedConditions.ElementIsVisible 返回 TimeoutException 即使元素是现在
这篇关于selenium.common.exceptions.TimeoutException 错误使用 WebDriverWait 和 expected_conditions 通过 Selenium 和 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!