18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
check if a checkbox is checked..but checkbox is _input element
Hello,
I have a checkbox that is given like this:
<input type="button" hidefocus="true" autocomplete="off" class="x-form-field x-form-checkbox" id="ext-gen1531" aria-checked="true" aria-invalid="false" data-errorqtip="" role="checkbox" aria-describedby="imagecheckbox-1369-errorEl" style="-moz-user-select: text;">
How can I check if it is checked or not?
Thank you!!!
I have a checkbox that is given like this:
<input type="button" hidefocus="true" autocomplete="off" class="x-form-field x-form-checkbox" id="ext-gen1531" aria-checked="true" aria-invalid="false" data-errorqtip="" role="checkbox" aria-describedby="imagecheckbox-1369-errorEl" style="-moz-user-select: text;">
How can I check if it is checked or not?
Thank you!!!
Comments
Seeing your code it seems that its an extjs checkbox and not the normal checkbox.
Here is an example:
Let me know if you face any problem.
Regards
Sumitra
if ($value=="1") {
if (_condition(!isSelected(_button(0)))) {
_click(_button(0));
}
}
else if ($value=="0") {
if (_condition(isSelected(_button(0)))) {
_click(_button(0));
}
}
But somehow the first case, which proves if the checkbox is unchecked, does not work..
I hope this helps.
Use something like..
_set($currentState, $myInput.getAttribute("aria-checked"));
... to assign the state of the checkbox to a variable.
I think in your case $myinput would be _button(0)
Im working with extjs checkboxes using...
If you set $value to true ("True" or "true") the checkbox will be checked or remain checked. If $value is set to false ("False" or "false") the check box will be unchecked or remain unchecked.
function _selectCheckBoxValueByLabel($checkBoxLabel, $value){
var $checked;
//string into boolean
if ($value === "True" || $value === "true" || $value === true){
$checked = true ;
}
if ($value === "False" || $value === "false" || $value === false) {
$checked = false ;
}
if ($checked === true || $checked === false){
var $myObject = _div(3, _near(_label($checkBoxLabel)));
var $myInput = _button (0, _in($myObject));
var $currentState;
_set($currentState, $myInput.getAttribute("aria-checked"));
var $checkedBoolean = false ;
if($currentState === "true"){
$checkedBoolean = true ;
}
if ($checked !== $checkedBoolean){
_click ($myInput);
}
} else {
_log ("Invalid $value in function _selectCheckBoxValueByLabel", "error");
}
}
I am exactly into the same issue trying to check a extjs checkbox of the input type "button". The issue here is that the button class name or any property of that element does not change if checked or unchecked. The only thing that changes is the Table classname for that checkbox now how can i get the table classname for the button which is in the <td>?
here is the table only table class changes when we check or uncheck the checkbox
class="x-field x-form-item x-field-default x-checkboxgroup-form-item x-form-dirty"
<table id="checkboxfield-1018" class="x-field x-form-item x-field-default x-checkboxgroup-form-item x-form-dirty" cellpadding="0" style="table-layout: auto;">
<tbody>
<tr id="checkboxfield-1018-inputRow">
<td id="checkboxfield-1018-labelCell" class="x-field-label-cell" width="105" valign="top" halign="left" style="display:none;">
<td id="checkboxfield-1018-bodyEl" class="x-form-item-body x-form-cb-wrap" role="presentation" colspan="3">
<input id="checkboxfield-1018-inputEl" class="x-form-field x-form-checkbox" type="button" hidefocus="true" autocomplete="off" aria-invalid="false" data-errorqtip="" style="-moz-user-select: text;">
<label id="checkboxfield-1018-boxLabelEl" class="x-form-cb-label x-form-cb-label-after" for="checkboxfield-1018-inputEl">DA Discrete Input/Output</label>
</td>
</tr>
</tbody>
</table
Any help is highly appreciated.
But the AssertTrue does not work for the function return (true/false)
var $Cname;
//var $CnameAftr;
var $butID;
// Constant class name for the checked object
var $val = "x-field x-form-item x-field-default x-checkboxgroup-form-item x-form-cb-checked";
_set($butID, _button(0, _near(_label($labelName))).id);
//_alert($butID);
var $trunc = $butID.substring(0, $butID.length - 8);
//_alert($trunc);
_set($Cname, _table($trunc).className);
if($Cname != $val) {
//return false;
_log("Not Checked");
}
else {
//return true;
_log("Checked");
}
}
isSelected('label');
_click(_button(0, _near(_label("label"))));
isSelected('label');
I hard coded it value since our app has very few checkboxes the right way is to use regular expression something like this
var $val = "/.*cb-checked.*/";
Hope this helps!!