2017-09-25 151 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() 
相關問題