方法一: if ($("#checkbox-id")get(0).checked) { // do something } 方法二: if($('#checkbox-id').is(':checked')) { // do something } 方法三: if ($('#checkbox-id').attr('checked')) { // do something }…
单选按钮是个常见的html元素,在网页中往往提供一组单选按钮来做选项. 这样在自动化测试用例中需要判断当前选中的按钮是否与预期的一直. 可以这样来操作: ${value} Get Element Attribute xpath=//form[@id='xxx']/*/input[@value='yyy']@checked 上面的关键字Get Element Attribute是获取html元素的指定属性的属性值.该关键的字的参数是 元素定位符后加上@要获取的属性名 上面例子是获取 c…
最近项目中需要用jquery判断input里checkbox是否被选中,发现用attr()获取不到复选框改变后的状态,最后查资料发现jQuery 1.6以后新增加了prop()方法,借用官方的一段描述就是: The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took pro…