2017-09-25 133 views
0

我在geb中使用了div.find("input","checked":contains("checked"))无法使用checked =“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") 
} 
+0

什么错误? –

+0

找不到该元素。 –

+0

你没有使用isSelected或没有 – iamsankalp89

回答

0

使用此语法复选框:

find("input:checkbox:checked") 

和这个收音机:

find("input:radio:checked") 

(也似乎是一个错别字seletedRadio word。)

+0

它不是复选框,它是一个单选按钮。谢谢 –

+0

好的。请再次检查答案 –

+0

groovy.lang.MissingMethodException:没有方法的签名:geb.waiting.UnknownWaitForEvaluationResult.text()适用于参数类型:()试过这个解决方案,并得到这个错误消息 –

0

在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>

0

使用此XPath和尝试

//input[@type='radio'][@checked=''] 
+0

没有说如何在JS中使用xpath,这不是很有用。 –

0

Geb has a module for working with radio buttons.所以,如果你的单选按钮是这样的:

<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() 
相关问题