HI dude ,
Use the following code to get your requirement done....
import com.thoughtworks.selenium.DefaultSelenium;
public class CheckBoxesStatusTest {
public static void main(String[] args) {
DefaultSelenium selenium = new DefaultSelenium("localhost", 8888,
"iexplore","
http://browsershots.org/");
selenium.start();
selenium.open("
http://browsershots.org/");
selenium.waitForPageToLoad("30000");
String checkBoxIds =selenium.getEval("function getCheckBoxsStatus()
{" //This is the function which will give the id's of of all check
boxes which are checked and unchecked
+"var cbgChkRefid='checked:';" // Some start variable for
check boxes check status
+"var chkCounter=0;"//counter for checked check boxes
+"var cbgNonChkRefid='unchecked:';" // Some start variable for
check boxes uncheck status
+"var unchkCounter=0;"//counter for unchecked check boxes
+"var docref = window.document;" // This variable holds the
document reference of a current selenium window
+"var
ipRef=docref.getElementById('startform').getElementsByTagName('input');" //
This variable holds the all input fields available in a form with id
'startform'
+"for(var k=0;k<ipRef.length;k++){"// This is a for loop for
iteration of the elements of the form
+"if(ipRef[k].type=='checkbox'){"// This if checks the input
element inside the form is check box or not
+"if(ipRef[k].checked){"// This if checks the input element
inside the form is check box and is checked
+"chkCounter=chkCounter+1;"
+"cbgChkRefid=cbgChkRefid+' '+ipRef[k].id;"// This variable
holds the string concatinating of the ids of the checked fields
+"}"// close of checked if
+"else{"// This if checks the input element inside the form is
check box and is unchecked
+"unchkCounter=unchkCounter+1;"
+"cbgNonChkRefid=cbgNonChkRefid+' '+ipRef[k].id;"// This
variable holds the string concatinating of the ids of the unchecked
fields
+"}"// close of else
+"}"// close of check box if if the input is of type check box
+"}"// End of for loop
+"return (cbgChkRefid+' cheked Checkboxes
Number'+chkCounter.toString()+'::'+cbgNonChkRefid+' uncheked
Checkboxes Number'+unchkCounter.toString()+'
totalNumberofcheckboxesonthePage:'+ipRef.length);"// Return statement
of the calling method getCheckBoxsStatus()
+"}"// close of function
+"getCheckBoxsStatus();");// invoking the method for getting
the checkboxes checked and unchecked as a String
checkBoxIds = checkBoxIds.replaceAll(":", "\n");
System.out.println("All checked and Unchecked IDS :\n
"+checkBoxIds.replaceAll(":", "\n"));
System.out.println("All checked and Unchecked IDS in line by line
format :\n "+checkBoxIds.replaceAll(" ", "\n"));
}
}
Let me know if you still need any help on this.....
BR,
Meerasaaheb Mohmmad.....