Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
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

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

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

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

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