假设我有以下 HTML5 片段:
<form method="get" action="logginValidation.php">
<input type="text" required="" name="username">
<button class="btn" type="submit">Se connecter</button>
</form>
使用 Selenium,我将字段留空并按下按钮。 表单没有像我预期的那样被验证,但是我如何验证这个字段是无效的,并且有一个与这个字段相关联的消息。
现在我没有调查的一件事是我正在使用加载了 JavaScript 库的 Twitter Bootstrap。我必须仔细检查这些库是否在耍我,验证是否真的来自 Firefox 浏览器。
最佳答案
来自 Selenium 文档:
Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).
这意味着 :required、:invalid 和 :valid 不是您可以选择与之交互的伪元素。
我通过对下一页上的文本执行 VerifyNotText 来解决此限制。不理想,但工作。
关于html - 如何使用 Selenium 测试是否为必填字段触发了 HTML5 验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12520852/