我測試使用HTML5約束驗證API生成錯誤彈出窗口的Web應用程序。 如何驗證硒測試彈出窗口中的文本? 我找不到合適的定位器。如何驗證由HTML5中的約束驗證API生成的消息中的文本?
1
A
回答
1
Selenium API不直接支持約束驗證。然而,你可以很容易地得到態,並用一段JavaScript代碼(JAVA)的消息:
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement field = driver.findElement(By.name("email"));
Boolean is_valid = (Boolean)js.executeScript("return arguments[0].checkValidity();", field);
String message = (String)js.executeScript("return arguments[0].validationMessage;", field);
注意的是,還可以使用getAttribute
得到validationMessage
即使它是一個屬性:
String message = driver.findElement(By.name("email")).getAttribute("validationMessage");
+0
非常感謝!我用.... getAttribute(「validationMessage」)並得到了消息。 – Alex
1
按你的鏈接提供的示例HTML代碼片段,解決你的問題是:
<form id="myForm">
<input id="eid" name="email_field" type="email" />
<input type="submit" />
</form>
我已經通過上面的html源代碼了,看着它非常清楚,但在點擊「提交查詢」後生成的驗證消息的源代碼中沒有html源代碼。
但是,我可以引導您拋出一個解決方法,它將像您在收到錯誤消息時工作一樣好。
請理解是這樣的:
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.
希望這是有意義的頂部,你最終可以幫助你。
相關問題
- 1. HTML5驗證消息?
- 2. 約束驗證
- 3. 如何全局設置Hibernate驗證約束的消息?
- 4. 驗證失敗時的消息的JSR驗證API中的本地化支持
- 5. GMF的生活約束 - 驗證
- 6. HTML5/JS約束驗證錯誤
- 7. 約束與驗證?
- 8. 約束驗證和淘汰賽驗證
- 9. 如何驗證pcap中的消息?
- 10. 我想驗證HTML5表單驗證中的文本
- 11. Bean驗證中的約束組
- 12. 流利的驗證驗證的生成文本框
- 13. 1無法設置驗證消息的約束
- 14. 只生成一個驗證消息的列中的列
- 15. 驗證消息
- 16. 驗證消息
- 17. 如何創建Symfony2.1驗證約束來驗證字符串中的標記數
- 18. 如何在Jackson生成的JSON模式中包含Bean驗證約束
- 19. MVC3驗證,不顯眼驗證 - 驗證消息的星號
- 20. 不同的驗證消息和驗證摘要消息
- 21. JQUERY/HTML5驗證 - 無法動態更新驗證消息
- 22. HTML5:與模式驗證自定義驗證消息
- 23. 在PHP中驗證XML並生成「可讀的」錯誤消息?
- 24. 如何使用HTML5 + CSS3驗證驗證ZK文本框?
- 25. JPA唯一約束驗證
- 26. 測試驗證約束
- 27. 模型約束驗證
- 28. 如何本地化Bean驗證消息
- 29. jQuery驗證成功的觸發消息
- 30. 顯示成功驗證的消息
你能告訴我們你的應用程序的源代碼以及你做了什麼 –
你不需要我的源代碼。我問了如何驗證這些消息中的文本:http://www.sagarganatra.com/2011/07/custom-validation-messages-for-html5.html – Alex
我認爲這是源代碼
–