Wednesday, January 19, 2011

Count the No of Check Box , Check them and print the values of the checkboxes



int checkboxcount=selenium.getXpathCount("//input[@type='checkbox']").intValue();
            System.out.println("The Number of checkbox :" +checkboxcount );

// intValue() function will  get the number the checkbox's in the page .

for (int i = 1; i <= checkboxcount; i++) {
                       if (selenium.isElementPresent("//input[@type='checkbox']"))
                       {
                           selenium.click("xpath=(//input[@type='checkbox'])[position()="+ i + "]");

                         String str= selenium.getText("xpath=(//label[@class='x-form-cb-label'])[position()="+ i + "]");
                 System.out.println("string----"+str );
}

Here checkbox count will be displayed and the count value is taken as checkboxcount into the "for"  loop
and "i" is incremented within the xpath . so that it will print all the values of the checkbox in the page

No comments:

Post a Comment