Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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)));

driver.findElement(By.id(chkboxid)).click();


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

Thanks

share|improve this question
add comment

2 Answers

up vote 1 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);
        Thread.sleep(500);
        // get the list of all available names

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

        System.out.println("dealTitle"+dealTitle);

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

        System.out.println("dealtitleCheck="+dealtitleCheck+"dealTitle="+dealTitle);

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

            // click on the check box for specific deal title
            // obtained from excel
            driver.findElement(By.id(chkboxid)).click();

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

            break;
        }//end of if condition

    }//end of for inner loop
    new WebDriverWait(driver, 10)
        .until(ExpectedConditions.presenceOfAllElementsLocatedBy(By
        .id("AdminMainContent_PagingCntrlDealSchedule_lbtnNext")));

    driver.findElement(
        By.id("AdminMainContent_PagingCntrlDealSchedule_lbtnNext"))
    .click();

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

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. –  Pramod Kumar G 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
add comment

Your Answer

 
discard

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.