[英]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.