python - selenium webriverwait 引发错误但没有描述

标签 python python-3.x selenium

这个:

element = wait.until(EC.element_to_be_clickable((By.ID, 'username')))

给出了这个错误:

Traceback (most recent call last):
  File "spammer.py", line 100, in <module>
    bot()
  File "spammer.py", line 75, in bot
    element = wait.until(EC.element_to_be_clickable((By.ID, 'inputSession')))
  File "C:\Users\matthijs\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

现在我的问题不仅是如何解决此问题,而且还包括为什么没有关于导致此错误发生的原因的消息。有什么想法吗?

最佳答案

您不会收到错误消息,因为 element_to_be_clickableuntil 的构建方式

expected_conditions

element_to_be_clickable 调用 visibility_of_element_ located,后者又调用 _find_element。这是此流程中唯一可能抛出未处理异常的函数

def _find_element(driver, by):
    try:
        return driver.find_element(*by)
    except NoSuchElementException as e:
        raise e
    except WebDriverException as e:
        raise e

正如您在 selenium.common.exceptions 中看到的那样,所有异常都默认为 stacktrace=None

exception selenium.common.exceptions.NoSuchElementException(msg=None, screen=None, stacktrace=None)

尽管 until尝试在引发异常之前获取堆栈跟踪

# partial function
def until(self, method, message=''):
    stacktrace = None

    while True:
        try:
            value = method(self._driver) # calls element_to_be_clickable.__call__ 
        except self._ignored_exceptions as exc: # NoSuchElementException
            stacktrace = getattr(exc, 'stacktrace', None)
    raise TimeoutException(message, screen, stacktrace)

堆栈跟踪仍然是None,因此没有任何内容可打印。

关于python - selenium webriverwait 引发错误但没有描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58817044/

相关文章:

python - 如何在 SQLAlchemy 中正确绑定(bind)对(元组数组、多维数组)?

python - tensorflow 中的优化器如何访问在单独函数中创建的变量

python - Process using multiprocessing 没有输出

python - 在不知道模式的情况下加载非常大的 JSON 文件?

python - pandas 无法推断带双引号的 str 类型

python - 为什么不将 if __name__ == '__main__' 放在模块的开头?

python - 为什么同一行声明的两个类对象指向一个对象?

java - Selenium WebDriver Java 代码无法在 eclipse 上执行 : Could not find the main class

javascript - nightwatch.js 在测试套件结束时暂停

selenium - BDD 测试应该由开发人员还是测试人员编写?