python - 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 的定位器。
解决方案
在您第一次打开网站时,电子邮件字段没有 class input-error
。尝试
email_field = self.located_element((By.CSS_SELECTOR, '[data-login-source="loginPage"] [name="email"]'))
推荐阅读
- java - 将参数反序列化为对象
- angular - Angular 会自动将带有参数的路由重定向回基本路由,为什么?
- php - 在水平线上列出值(php foreach)
- visual-studio-2019 - 使用 vs 表单将 pdf 文件存储在 MS Access 附件字段中
- java - 双 forEach 流过集合和哈希图 Java
- ruby-on-rails - 更好的数据类型来存储长 ID
- maxima - 如何在最大值 [v5.44] 中更改线条的线条粗细(implicit_plot)?
- c# - 如何将数组 [] 转换为 HttpPostedFileBase
- android - 在recyclerview kotlin中插入firebase快照
- spring - 如何在论坛项目中实现类似的功能 [spring-boot]