首页 > 解决方案 > raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Assertion failed

问题描述

我对 Selenium Webdriver 有问题,试图定位元素,程序给出错误“引发 TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Assertion failed”

我的代码使用页面对象模型:我的代码:第一部分 -

  def located_element(self, locator):
        wait = WebDriverWait(self.driver, 30)
        element = wait.until(EC.presence_of_element_located(locator))
        return element

第二部分

 def enter_email(self, user):
        email_field = self.located_element(self.locator.Email)
        email_field.click()
        email_field.send_keys(Users.get_user(user)["email"])

第三名(跑步)

我尝试了一些相关问题的建议,但对我没有帮助。起初,它找不到元素,这就是我添加 EC 的原因,但现在它引发了错误。请帮助我,我该如何处理异常。我也尝试过使用 xpath 和 css-selector 的定位器。

标签: pythonseleniumtimeoutexception

解决方案


在您第一次打开网站时,电子邮件字段没有 class input-error。尝试

email_field = self.located_element((By.CSS_SELECTOR, '[data-login-source="loginPage"] [name="email"]'))

推荐阅读