【问题标题】:How to locate an error message in the website dev options if the inspector isn't finding it如果检查员没有找到错误消息,如何在网站开发选项中找到它
【发布时间】:2019-10-07 01:40:54
【问题描述】:

我有这个网站https://www.ultimateqa.com/complicated-page/

其中有一个“获取最新博客文章”字段我想自动显示错误消息,但是当我添加一个无效的电子邮件地址,即 test123.com 时,会返回错误响应,但不会显示它的路径在开发者选项中,所以我无法创建脚本并验证它。

我可以在属性中看到验证消息,但在那里找不到它的路径。

任何帮助将不胜感激。

【问题讨论】:

    标签: java html selenium selenium-chromedriver


    【解决方案1】:

    您所指的弹出窗口是 Constraint API 的 [https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5/Constraint_validation#Controlling_the_text_of_constraints_violation] element.setCustomValidity() 方法的结果。

    您可以像这样使用“validationMessage”属性:

        driver.get("https://www.ultimateqa.com/complicated-page/");
        WebElement inputElement = driver.findElement(By.xpath("//*[@id=\"subscribe-field-blog_subscription-2\"]"));
        System.out.println(inputElement.getAttribute("validationMessage"));
        inputElement.sendKeys("test");
        System.out.println(inputElement.getAttribute("validationMessage"));
        inputElement.sendKeys("test@email.com");
        System.out.println(inputElement.getAttribute("validationMessage"));
        driver.quit();
    

    输出:

    Please fill out this field.
    Please include an '@' in the email address. 'test' is missing an '@'.
    

    最后一个打印是空的,这是一封很好的电子邮件

    【讨论】:

    • 非常感谢,我什至没有想到这可能是一个 api 响应;-))
    • 很高兴听到它对您有所帮助。如果您认为它解决了您的问题,请接受我的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多