如何检查是否使用硒触发了HTML5验证? [英] How to check if an HTML5 validation was triggered using selenium?

查看:140
本文介绍了如何检查是否使用硒触发了HTML5验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用Selenium测试我的webapp。 webapp中的所有表单验证都是使用HTML5表单验证完成的。有什么办法来断言,如果表单/输入验证是使用Selenium触发的?

If testing my webapp using Selenium. All the form validation in the webapp is done using HTML5 form validations. Is there any way to assert if a form/input validation was triggered using Selenium?

推荐答案

支持HTML5的浏览器(使用Java和WebDriver,但也可以在其他任何地方使用):

A search like this does the trick in HTML5-aware browsers (using Java and WebDriver, but should be usable anywhere else, too):

// looks for an element that has been marked as required on a submit attempt
WebElement elem1 = driver.findElement(By.cssSelector("input:required"));
// looks for an element that has been marked as invalid on a submit attempt
WebElement elem2 = driver.findElement(By.cssSelector("input:invalid"));

可用的CSS伪类是:

  • :required
  • :optional
  • :valid
  • :invalid

这篇关于如何检查是否使用硒触发了HTML5验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆