Search
Display results as :
Advanced Search
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
narendercb
Posts : 8
Join date : 2013-06-25

how to select checkbox whose id is not known or dynamic with selenium RC Empty how to select checkbox whose id is not known or dynamic with selenium RC

on Tue Jun 25, 2013 8:44 pm
Hi All,
I need to select checkbox in the web application whose id is  appended dynamically,Can you please help me

Thanks,
Narender chary

following is the html code snip from the web application
--------------------------‹‹
<table id="someid">
<tr>
<td>
<input id="someDynamicId" type="checkbox" .....>mycheckbox
</td>
</tr>
</table>

my requirement is
1.check checkbox whose value/lable is mycheckbox and if this matches select this checkbox
2.i need to do this in Selenium RC.
avatar
mail2prassad
Amateur
Amateur
Posts : 41
Join date : 2013-06-05

how to select checkbox whose id is not known or dynamic with selenium RC Empty Re: how to select checkbox whose id is not known or dynamic with selenium RC

on Tue Jun 25, 2013 10:47 pm
The following block of code should do, but this is WebDriver not RC. The similar logic should work in RC also.


Code:
//To get the check box with value MY_CHECKBOX_VALUE
WebElement checkBox = driver.findElement(By.xpath("//input[@type = 'checkbox' and @value = '<MY_CHECKBOX_VALUE>']"));

//To select the checkbox
if(checkBox != null)
checkBox.click();
avatar
narendercb
Posts : 8
Join date : 2013-06-25

how to select checkbox whose id is not known or dynamic with selenium RC Empty Re: how to select checkbox whose id is not known or dynamic with selenium RC

on Tue Jun 25, 2013 11:35 pm
Hi,
the above mention solution driver.findElement(By.xpath("//input[@type='checkbox' and @value='my_checkbox_value']")) will work if html code like below

<td>
<input id="someDynamicId" type="checkbox" .....>mycheckbox
</td>

but hovewer my actual html source  is something like below
--------
<table id="someid">
<tr>
<td>
<input id="someDynamicId" type="checkbox" .....>
</td>
<td>mycheckbox</td>
</tr>
</table>

Please suggest
avatar
narendercb
Posts : 8
Join date : 2013-06-25

how to select checkbox whose id is not known or dynamic with selenium RC Empty Re: how to select checkbox whose id is not known or dynamic with selenium RC

on Thu Jun 27, 2013 1:44 am
Hi,
i have done following steps and its worked
1.read all the check box id's in web page like below
 int checkboxCount = selenium.getXpathCount("//input[@type='checkbox']").intValue();
              String checkBoxIds[]=new String[checkboxCount];
for (int i = 1; i < checkboxCount + 1; i++) {
            System.out.println(selenium.getAttribute("//body/descendant::input[@type='checkbox'][" + i + "]@id"));
            if (selenium.getAttribute("//body/descendant::input[@type='checkbox'][" + i + "]@id").startsWith("check")) {
                checkBoxIds[i-1]=selenium.getAttribute("//body/descendant::input[@type='checkbox'][" + i + "]@id");
            }
            
        }
            
        }

2.Iterate all the rows in the table and select the check box whose lable is matched with the requirement
    Number num =selenium.getXpathCount("//html/body/div/div[1]/table[1]/tbody/tr[2]/td[2]/div[1]/div[4]/div[3]/table/tbody[2]/tr/");
            int i= num.intValue();
            for (int j = 1; j <i+1; j++) {
                      if (selenium.getText("//html/body/div/div[1]/table[1]/tbody/tr[2]/td[2]/div[1]/div[4]/div[3]/table/tbody[2]/tr["+j+"]/td[4]").equals(messageToDelete)) {
                           selenium.check("//input[@id='"+checkBoxIds[j-1]+"']");
                   }
            }
            selenium.click("id_of_target");

Thanks,
Sponsored content

how to select checkbox whose id is not known or dynamic with selenium RC Empty Re: how to select checkbox whose id is not known or dynamic with selenium RC

Back to top
Permissions in this forum:
You cannot reply to topics in this forum