html - 如何使用 Selenium 验证登录文本框验证错误消息
问题描述
网址 - https://www.vtiger.com/begin-free-trial
输入无效的电子邮件地址,例如“abcde”,然后单击下一步按钮。您会注意到一条错误消息,该消息将显示 4/5 秒(下图)
我们如何验证此错误消息,我也无法获取此错误消息。
解决方案
试试下面的代码 -
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 '@'.
注意 - 如果它解决了您的问题,请标记为答案。
推荐阅读
- c++ - 试图理解代表此代码不会编译 c++ 11
- google-bigquery - 追加到python中的表
- javascript - 为什么我不能在网页上显示粒子?
- cron - Crontab 在一天中的两个小时运行,但其中一个小时不包括一周中的某些天
- featuretools - 在 Featuretools 中更改自上次基元以来的时间单位
- python - 将文件与 FileField 关联而不创建文件副本?
- linux - linux内核加载后如何让linux驱动程序检测和使用设备?
- python - 如何在 csv 文件中搜索存储在另一个 csv 文件中的关键字?
- database - 如何在 SQL 中对具有多列的时间序列数据进行下采样?
- c# - 有没有办法通过使用安装在应用程序托管服务器上的打印机从 Asp.Net MVC 应用程序“打印”(通过 c# 代码)?