Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a test case where I shall enter details for a deal to be scheduled for a future date and time. I have a pop up which is listing all existing deals having check boxes for selecting one of them independently. I could create and run the test case successfully only once but on further executions the first check box is always getting selected.

//steps to click on a check box 

new WebDriverWait(driver, 100).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//span[contains(.,'CAR')]")));

String s=driver.findElement(By.xpath("//span[contains(.,'CAR')]")).getAttribute("id");

int number=Integer.parseInt(s.split("_")[3]);

String chkboxid="AdminMainContent_grdDealDetails_chkSelect_"+number;

new WebDriverWait(driver, 100).until(ExpectedConditions.presenceOfAllElementsLocatedBy(;


//click on ok button
new WebDriverWait(driver,100).until(ExpectedConditions.presenceOfAllElementsLocatedBy("AdminMainContent_lbtnOkGrid")));


share|improve this question
up vote 2 down vote accepted

I got solved issue using below code. The issue was with a for loop that I had used to iterate through all check box ids and if the page doesn't have it will click on next button. Actually I had misplaced the click on next button.

for (int page = 1; page <= Integer.parseInt(totaPage); page++) {
    String dealTitle;

    String dealtitleCheck = s.getCell(2, 4).getContents().trim();

// {

    System.out.println("current page number is)" + page);
    for (int i = 0; i < 10; i++) {
        //System.out.println("I=" + i);
        // get the list of all available names

        dealTitle = driver.findElement("AdminMainContent_grdDealDetails_lblTitle_" + i)).getAttribute("innerHTML").trim();


        // getting the id of car from excel
        // String dealtitleCheck = s.getCell(2, 4).getContents();


        boolean stat = dealTitle.equals(dealtitleCheck);

        System.out.println("equal status="+stat);

        if (dealTitle.equals(dealtitleCheck)) {

            // System.out.println("you got it in"+i);
            // getting id of check box to select
            String chkboxid = "AdminMainContent_grdDealDetails_chkSelect_" + i;

            // waiting
            new WebDriveWait(driver, 100)

            // click on the check box for specific deal title
            // obtained from excel

            //click on ok button
            new WebDriverWait(driver, 100).until(ExpectedConditions.presenceOfAllElementsLocatedBy("AdminMainContent_lbtnOkGrid")));

        }//end of if condition

    }//end of for inner loop
    new WebDriverWait(driver, 10)


}//end of for outer loop
share|improve this answer

How is the test getting executed further? In a loop? Is number and chkboxid re-generated with each execution?

Check that the id for each checkbox are what you are expecting for each execution.

share|improve this answer
Thanks lars for your comment.Well i got issue solved.The issue was with a for loop that i had used to iterate through all check box id and if the page doesnt have it will click on next button.Actually i had misplaced the click on next button. – Tester Oct 12 '12 at 8:25
Cool. When you have a chance then mark your answer as the correct one. – Lars Nordin Oct 12 '12 at 11:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.