【问题标题】:How to handle error message if button gets pressed in selenium如果在硒中按下按钮,如何处理错误消息
【发布时间】:2021-07-09 12:00:17
【问题描述】:

您好,我有一个按钮,它告诉您是否在 Yahoo 邮件中使用了电话号码 但我想制作一个程序来检查雅虎按钮中的数字是否会被点击和重定向,但如果数字不存在,它将

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

这不工作我不知道为什么

网站是https://login.yahoo.com/?.lang=en-US&src=homepage&.done=https%3A%2F%2Fwww.yahoo.com%2F&pspid=2023538075&activity=ybar-signin

这是如果数字存在会发生什么的图片

如果不是,那么这就是页面的样子

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    如果要验证是否

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多