There was an error in this gadget

Technical Project Lead @ Huawei Technologies

My photo
Bangalore/Hyderabad, Karnataka/Andhra Pradesh, India
Have an overall 10 + yrs of experience Currently working as an Senior Architect.Expertise in design,implementation of Automation frameworks for Opensource automation tools like Selenium,Jmeter, Webdriver,Appium, Robotium Expertise in integrating Test & ALM Management tools like Rally,Qmetry,JIRA-Zephyr with Automation frameworks Expertise in design and developmenet Mobile Automation frameworks for tools like Appium, Robotium Remote Control,Cucumber BDD


Monday, October 11, 2010

How to get the count of Checkboxes and Select them all

Lets take a webpage having multiple check boxes. How do I get the count of all checkboxes and how do I select them
1.Go to the following link and you will find checkboxes under Search Language. Below Code Snippet instructs selenium to get the check box count and select all the checkboxes one by one

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class AjaxTests {
    static SeleniumServer server;
    static Selenium selenium;

    public static void setUpBeforeClass() throws Exception {
        server = new SeleniumServer();

        selenium = new DefaultSelenium("localhost", 4444, "*iexploreproxy",

    public static void tearDownAfterClass() throws Exception {

    public void testAllCheckBoxes(){
         //Get the count of all available check boxes

         int checkBoxCount = selenium.getXpathCount("//form[@name='langform']/table[5]/tbody/tr[2]/td[3]
        //Print the Check box count
        System.out.println("Total Number of Check box count is : " + checkBoxCount );
        int count = selenium.getXpathCount("//form[@name='langform']/table[5]/tbody/tr[2]/td[3]/table/tbody
        for (int i = 1; i <=4; i++) {
            for (int j = 1; j <= count; j++) {
                if(i == 4 && j == 11){
                selenium.check("//form[@name='langform']/table[5]/tbody/tr[2]/td[3]/table/tbody/tr/td[" + i +
                              "]/font[1]/label"+"[" + j +"]/input");


  1. Hi Sir ,

    Ur blog is really help .. i have a doubt in counting the checkbox ...

    Wat does the Xpath //form[@name='langform']/table[5]/tbody/tr[2]/td[3]

    stand for in the wensite ???

  2. hi ,

    this is gousia,I am trying to learning selenium on my own,but at some point i am struck,please help me out if there is any helpful material or you can provide guidance....

    Let me know

  3. right now I have a scenario,
    that is
    there is a checkbox with label "show only my items"when we check the check box,it should show the widgets created by the current user.
    if we uncheck it should show all the other user widgets also
    I was trying by Xpath ,i am not getting ,
    please help me out

  4. Hi your blog is very good.I have one doubt is it possible to apply automated testing using java selenium for a wordpress page having images graphs,pie charts?
    Please reply soon if possible post some related example
    thank you

    1. Yes, You should be able to automate word press