title: How to select checkbox by passing the checkbox name - using Selenium / Webdriver
body: <p>HTML source page:</p>
  
  <p>//start:</p>
  
  <pre><code>    &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div id="ctl00_ContentPlaceHolder1_control1_pnlEdit"&gt;
  
       &lt;h2&gt;
          &lt;span id="ctl00_ContentPlaceHolder1_control1_lblEditHeader"&gt;Add New&lt;/span&gt;&lt;/h2&gt;
      &lt;br /&gt;&lt;br /&gt;
  
  
      &lt;div&gt;
          &lt;table class="DetailsView" cellspacing="0" cellpadding="5" rules="all" border="1" id="ctl00_ContentPlaceHolder1_control1" style="height:50px;width:600px;border-collapse:collapse;"&gt;
              &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;              
                      &amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;&lt;tr&gt;
                  &lt;td&gt;Category&lt;/td&gt;&lt;td&gt;  
                      &lt;div style="border-style: solid; border-width: 1px; border-color: inherit; overflow:auto; height:200px; width:300px;" &gt;
                          &lt;table id="ctl00_ContentPlaceHolder1_control1_lstCat" class="CheckBoxList" selectionmode="Multiple" border="0"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:0px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_0" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$0" /&gt;&lt;label for="ctl00_ContentPlaceHolder1_control1_lstCat_0"&gt;Item 
                              1&lt;/label&gt;&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;&lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:15px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_1" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$1" /&gt;Item 
                              1-2&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;&lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:15px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_2" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$2" /&gt;&lt;span&gt;Item 
                              1-3&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;&lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:15px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_3" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$3" /&gt;&lt;span&gt;Item 
                              1-4&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;&lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:0px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_4" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$4" /&gt;&lt;span&gt;Item 
                              2&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;&lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:15px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_5" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$5" /&gt;&lt;span&gt;Item 
                              2-1&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;&lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:0px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_6" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$6" /&gt;&lt;span&gt;Item 
                              3&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;&lt;tr&gt;
                          &lt;td&gt;&lt;span style="padding-left:15px;"&gt;&lt;input id="ctl00_ContentPlaceHolder1_control1_lstCat_7" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$7" /&gt;&lt;span&gt;Item 
                              3-1&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
                      &lt;/tr&gt;
  
                  &lt;/table&gt;     
  
                      &lt;/div&gt;                                                   
                  &lt;/td&gt;
              &lt;/tr&gt;&lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;    
  
  &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>//end</p>
  
  <p><strong>EDIT:</strong> <a href="https://stackoverflow.com/questions/11406091/selecting-element-followed-by-text-with-selenium-webdriver/11409449#11409449">Selecting Element followed by text with Selenium WebDriver</a></p>
  
  <p>my question is similar to the above post</p>
  
  <p><strong>END EDIT</strong></p>
  
  <p>Below is my page source code it renders at runtime</p>
  
  <p>i have unique checkbox id that generates for each checkbox for an example:</p>
  
  <pre><code>ctl00_ContentPlaceHolder1_Control1_stCat_1
  ctl00_ContentPlaceHolder1_Control1_stCat_2
  ctl00_ContentPlaceHolder1_Control1_stCat_3
  ..........................................
  ctl00_ContentPlaceHolder1_Control1_stCat_8
  etc..............
  </code></pre>
  
  <p>My requirement is: if I pass the <code>Checkbox Text</code> then it should Select the related checkbox
  for an example:</p>
  
  <p>if I pass the Checkbox Text = <code>Some text present.....</code> then Checkbox Id <code>ctl00_ContentPlaceHolder1_Control1_stCat_1</code> should be checked</p>
  
  <p>PS: <code>Item 1, Item 2</code> is just an example in the real data I have some random names</p>
  
  <p>Below is my html code generate:</p>
  
  <pre><code>&lt;tr&gt;
  &lt;td&gt;Category&lt;/td&gt;
  &lt;td&gt;
  &lt;div style="border-style: solid; border-width: 1px; border-color: inherit; overflow:auto; height:200px; width:300px;"&gt;
  &lt;table id="ctl00_ContentPlaceHolder1_AddControl1_lstCat" class="CheckBoxList" border="0" selectionmode="Multiple"&gt;
  &lt;tbody&gt;
  &lt;tr&gt; 
    &lt;td&gt;
      &lt;span style="padding-left:15px;"&gt;
      &lt;input id="ctl00_ContentPlaceHolder1_Control1_stCat_1" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$1"/&gt;
      &lt;label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_8"&gt;Item 1&lt;/label&gt;
      &lt;/span&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt; 
    &lt;td&gt;
      &lt;span style="padding-left:15px;"&gt;
      &lt;input id="ctl00_ContentPlaceHolder1_Control1_stCat_2" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$2"/&gt;
      &lt;label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_2"&gt;Item 2&lt;/label&gt;
      &lt;/span&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt; 
    &lt;td&gt;
      &lt;span style="padding-left:15px;"&gt;
      &lt;input id="ctl00_ContentPlaceHolder1_Control1_stCat_3" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$3"/&gt;
      &lt;label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_3"&gt;Item 3&lt;/label&gt;
      &lt;/span&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  
  .............
  ..............
  ................
  .................
  more...............
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/SOM6F.png" alt="enter image description here"></p>