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.
Count checkboxes and assert option
Hi i'm new one using sahi and i want some help with a test i'm trying to do.
What i'm trying to do is to count how many checkboxes are selected in a specific group, in this case all
of them have the same name and Sahi shows this: _checkbox("member_lab_id[ i ]") for each one after the first one, and for the first it shows only _checkbox("member_lab_id").
Can you help me with this?? And if can be possible in the count not taking into account the agreement checkbox??
Thnx
The Html is something like this:
Also i have to use a try catch with an assert because i don't know how to put this into an if structure because what it does is check if the label exists wich is from an error, and if it doesn't this means that the submit was ok and it was redirecting to another page were it needs to do another submit.
There exists an option that return a boolean value if the object exists or is there another way to do this?
What i'm trying to do is to count how many checkboxes are selected in a specific group, in this case all
of them have the same name and Sahi shows this: _checkbox("member_lab_id[ i ]") for each one after the first one, and for the first it shows only _checkbox("member_lab_id").
Can you help me with this?? And if can be possible in the count not taking into account the agreement checkbox??
Thnx
The Html is something like this:
<input type="checkbox" name="member_lab_id" value="6791" id="user_add:elements:member_lab_id:6791" onclick="displayLabMsg();"> Advanced Light Microscopy/ Spectroscopy<br>
<input type="checkbox" name="member_lab_id" value="6794" id="user_add:elements:member_lab_id:6794" onclick="displayLabMsg();"> Electron Imaging Center for NanoMachines (EICN)<br>
<input type="checkbox" name="member_lab_id" value="6794-ua" id="user_add:elements:member_lab_id:6794-ua" onclick="displayLabMsg();"> <a href="#" onclick="window.open('user-agreement?lab_id=6794','userAgreement','width=400,height=500,scrollbars=yes,location=0');">I have read and understood the user agreement</a><br></span>
<input type="checkbox" name="member_lab_id" value="12849" id="user_add:elements:member_lab_id:12849" onclick="displayLabMsg();"> Integrated NanoMaterials Lab<br><input type="checkbox" name="member_lab_id" value="6797" id="user_add:elements:member_lab_id:6797" onclick="displayLabMsg();"> Integrated Systems Nanofabrication Cleanroom (ISNC)<br><input type="checkbox" name="member_lab_id" value="341302" id="user_add:elements:member_lab_id:341302" onclick="displayLabMsg();"> Lab Test 1<span id="req_341302" style="padding-left: 2em; font-style: italic; font-size: 9pt; color: rgb(153, 62, 27); display: none; ">
<input type="checkbox" name="member_lab_id" value="341302-ua" id="user_add:elements:member_lab_id:341302-ua" onclick="displayLabMsg();"> <a href="#" onclick="window.open('user-agreement?lab_id=341302','userAgreement','width=400,height=500,scrollbars=yes,location=0');">I have read and understood the user agreement</a><br></span>
<input type="checkbox" name="member_lab_id" value="341440" id="user_add:elements:member_lab_id:341440" onclick="displayLabMsg();"> Lab Test 2<br>
<input type="checkbox" name="member_lab_id" value="341440-ua" id="user_add:elements:member_lab_id:341440-ua" onclick="displayLabMsg();"> <a href="#" onclick="window.open('user-agreement?lab_id=341440','userAgreement','width=400,height=500,scrollbars=yes,location=0');">I have read and understood the user agreement</a><br></span>
<input type="checkbox" name="member_lab_id" value="6800" id="user_add:elements:member_lab_id:6800" onclick="displayLabMsg();"> Macro-Scale Imaging Lab<br><input type="checkbox" name="member_lab_id" value="13691" id="user_add:elements:member_lab_id:13691" onclick="displayLabMsg();"> Molecular Instrumentation Center (MIC)<br><input type="checkbox" name="member_lab_id" value="6803" id="user_add:elements:member_lab_id:6803" onclick="displayLabMsg();"> Molecular Screening Shared Resource (MSSR)
<input type="checkbox" name="member_lab_id" value="6806" id="user_add:elements:member_lab_id:6806" onclick="displayLabMsg();"> Nano & Pico Characterization Lab<span id="req_6806" style="padding-left: 2em; font-style: italic; font-size: 9pt; color: rgb(153, 62, 27); display: none; ">
Also i have to use a try catch with an assert because i don't know how to put this into an if structure because what it does is check if the label exists wich is from an error, and if it doesn't this means that the submit was ok and it was redirecting to another page were it needs to do another submit.
There exists an option that return a boolean value if the object exists or is there another way to do this?
_click(_submit(0));
try {
if (_condition(_assertContainsText("This email is already registered. Please enter a new email", _div("form-label-error[3]")) != null)) {
_log ( "This email is already registered. Please enter a new email", "info")
}
} catch (error) {
_click(_button(0));
_click(_submit(0));
_click(_link("Logout"));
}
This discussion has been closed.
Comments
_checkbox("member_lab_id") is the same as _checkbox("member_lab_id[0]").
To get the count in your case, you could use
var $checkBoxCount = 0;
_set($checkBoxCount, document.getElementsByName("member_lab_id").length);
To check for the content in a IF,
if (_condition(_getText(_div("form-label-error[3]")).indexOf("This email is already registered. Please enter a new email") != -1)) {
_log ( "This email is already registered. Please enter a new email", "info")
} else {
// ...
}