首页 > 解决方案 > 如何使用 Selenium 验证登录文本框验证错误消息

问题描述

网址 - https://www.vtiger.com/begin-free-trial

输入无效的电子邮件地址,例如“abcde”,然后单击下一步按钮。您会注意到一条错误消息,该消息将显示 4/5 秒(下图)

我们如何验证此错误消息,我也无法获取此错误消息。

在此处输入图像描述

标签: htmlseleniumselenium-webdriverwebdriverwaitconstraint-validation

解决方案


试试下面的代码 -

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
action = ActionChains(driver)

driver.get('https://www.vtiger.com/begin-free-trial/')

driver.find_element_by_name('email').send_keys("xyz")
driver.find_element_by_xpath('//button[contains(text(),"Next")]').click()

messagetoVerify = "Please include an '@' in the email address. 'xyz' is missing an '@'."
myValidationmsg = driver.find_element(By.NAME, 'email').get_attribute("validationMessage")

if myValidationmsg == messagetoVerify:
    print("Verified Validation Message")

输出 -

Please include an '@' in the email address. 'xyz' is missing an '@'.

注意 - 如果它解决了您的问题,请标记为答案。


推荐阅读