Java 如何验证HTML5中约束验证API生成的消息中的文本?

Java 如何验证HTML5中约束验证API生成的消息中的文本?,java,html,selenium-webdriver,Java,Html,Selenium Webdriver,我测试使用HTML5约束验证API生成错误弹出窗口的web应用程序。 如何验证selenium测试中弹出窗口中的文本? 我找不到合适的定位器。Selenium API不直接支持约束验证。但是,您可以使用一段JavaScript(Java)轻松获取状态和消息: JavascriptExecutor js=(JavascriptExecutor)驱动程序; WebElement字段=driver.findElement(By.name(“电子邮件”)); Boolean is_valid=(Bool

我测试使用HTML5约束验证API生成错误弹出窗口的web应用程序。 如何验证selenium测试中弹出窗口中的文本?
我找不到合适的定位器。

Selenium API不直接支持约束验证。但是,您可以使用一段JavaScript(Java)轻松获取状态和消息:

JavascriptExecutor js=(JavascriptExecutor)驱动程序;
WebElement字段=driver.findElement(By.name(“电子邮件”));
Boolean is_valid=(Boolean)js.executeScript(“返回参数[0].checkValidity();”,字段);
字符串消息=(字符串)js.executeScript(“返回参数[0].validationMessage;”,字段);
请注意,也可以使用
getAttribute
获取
validationMessage
,即使它是一个属性:

String message=driver.findElement(By.name(“email”)).getAttribute(“validationMessage”);

根据您提供的链接,解决您问题的示例HTML代码片段是:

<form id="myForm">
<input id="eid" name="email_field" type="email" />
<input type="submit" />
</form>

希望这对你有意义,并最终帮助你。

你能告诉我们你的应用程序的源代码和你所做的事情吗?你不需要我的源代码。我问如何验证这些消息中的文本:我想这是你的网站中的源代码,这些消息在图像中。从图片中你无法获得文本。非常感谢!我使用了…getAttribute(“validationMessage”)并得到了消息。
1.Please observer source code of input boxes with Constraint Validation API in HTML5?
2.you will clearly see that its attribute defines what type of data they can take in 
  our example attribute name and type.
3.they both clearly say that above html code will take input in the form of email only.
4.so your logic will be to check value entered in the input box is of the type of 
  email or not.if its email then pass the test otherwise fail.