如果在硒中按下按钮,如何处理错误消息
How to handle error message if button gets pressed in selenium
您好,我有一个按钮可以告诉您 Yahoo 邮件中是否使用了 phone 号码
但我想制作一个程序来检查雅虎按钮中的号码是否会被点击和重定向,但如果号码不存在它将
driver.get("https://login.yahoo.com/?.lang=en-US&src=homepage&.done=https%3A%2F%2Fwww.yahoo.com%2F&pspid=2023538075&activity=ybar-signin")
lol=0
log_in_btn= driver.find_element_by_id("login-username")
error= driver.find_element_by_xpath("//*[@id='username-error']")
log_in_btn.send_keys(new_list[lol])
btn= driver.find_element_by_id("login-signin").click()
print(error.text
这不起作用我不知道为什么
这是数字存在时会发生什么的图片
如果不是,那么这就是页面的样子
如果要验证是否
Sorry, we don't recognize this phone number.
消息是否出现。
这个css:
p[data-error]
表示错误信息。
代码:
try:
if len(driver.find_elements_by_css_selector("p[data-error]")) > 0 :
print("Error is present and the messgae is ", driver.find_element_by_css_selector("p[data-error]").text)
else:
print("No error msg found")
except:
print("There an issue, please check the code again.")
pass
您好,我有一个按钮可以告诉您 Yahoo 邮件中是否使用了 phone 号码 但我想制作一个程序来检查雅虎按钮中的号码是否会被点击和重定向,但如果号码不存在它将
driver.get("https://login.yahoo.com/?.lang=en-US&src=homepage&.done=https%3A%2F%2Fwww.yahoo.com%2F&pspid=2023538075&activity=ybar-signin")
lol=0
log_in_btn= driver.find_element_by_id("login-username")
error= driver.find_element_by_xpath("//*[@id='username-error']")
log_in_btn.send_keys(new_list[lol])
btn= driver.find_element_by_id("login-signin").click()
print(error.text
这不起作用我不知道为什么
这是数字存在时会发生什么的图片
如果不是,那么这就是页面的样子
如果要验证是否
Sorry, we don't recognize this phone number.
消息是否出现。
这个css:
p[data-error]
表示错误信息。
代码:
try:
if len(driver.find_elements_by_css_selector("p[data-error]")) > 0 :
print("Error is present and the messgae is ", driver.find_element_by_css_selector("p[data-error]").text)
else:
print("No error msg found")
except:
print("There an issue, please check the code again.")
pass