我在使用 Selenium Webdriver 时遇到问题,尝试定位该元素时,程序给出错误“raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Assertion failed”
我的代码使用页面对象模型: 我的代码: 第 1 部分 -
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 来定位。
最佳答案
第一次打开网站时,电子邮件字段没有类input-error
。尝试一下
email_field = self.located_element((By.CSS_SELECTOR, '[data-login-source="loginPage"] [name="email"]'))
关于python - 引发TimeoutException(消息,屏幕,堆栈跟踪)selenium.common.exceptions.TimeoutException : Message: Assertion failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60294302/