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(By.id(chkboxid)));


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


2 Answers 2


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(
        By.id("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(By.id("AdminMainContent_lbtnOkGrid")));

        }//end of if condition

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


}//end of for outer loop

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.

  • 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.
    – Pramod
    Oct 12, 2012 at 8:25
  • Cool. When you have a chance then mark your answer as the correct one. Oct 12, 2012 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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