[英]Unable to find radio button element using checked=“Checked” attribute
我在div.find("input","checked":contains("checked"))
使用了div.find("input","checked":contains("checked"))
。
这是我用来识别网页上选中的单选按钮的实际代码段,但是它在"input","checked":contains("checked")
上给出了错误"input","checked":contains("checked")
seletedRadio(wait:true,required:false){
$("tbody.option-group-container")
.getAt(0)
.find("input","checked":contains("checked"))
.next("label")
.find("span.label-text")
}
使用此语法作为复选框:
find("input:checkbox:checked")
对于收音机:
find("input:radio:checked")
(也似乎在seletedRadio单词中有错别字。)
在jQuery中,您可以使用选择器input[name=value]:checked
以获取所选值。 检查下面的例子
console.log($('input[name=gender]:checked').val());
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <label for=""><input type="radio" name = 'gender' value = 'M' > Male</label> <label for=""><input type="radio" name = 'gender' value = 'F' checked> Female</label>
使用这个xpath并尝试
//input[@type='radio'][@checked='']
Geb有一个用于处理单选按钮的模块。 因此,如果您的单选按钮类似于:
<input type="radio" id="option1" name="radio" value="option1">
<input type="radio" id="option2" name="radio" value="option2">
您可以有一个选择器,例如:
radioMod {$("input", name: "radio").module(RadioButtons)}
并使用getChecked返回值:
radioMod.getChecked()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.