title: I have a table of rows with checkboxes in columns. How do i select a particular checkbox
body: <p>I have the following HTML structure. A table with rows, the 2nd column has the text displayed e.g. Title (in row 1), FName (in row 2), SNAME (in row3), GENDER etc. 
  The 3rd column has a checkbox for each row.
  I am trying to select a particular checkbox.  E.g. my method will accept a parameter (the name of the text value in the row e.g. TITLE).
  The method will select the checkbox for TITLE.
  When i call the method again with parameter FNAME, the checkbox for FNAME will be clicked.
  I am using Selenium Webdriver with Python</p>
  
  <p>I have tried the following XPATH to identify the checkbox:</p>
  
  <pre><code>//span[@title="TITLE" and contains(text(), "TITLE")]/following-sibling::*
  
  //span [text()="TITLE"]/../../preceding-sibling::td/div/input[@type="checkbox"]
  </code></pre>
  
  <p>These do not find the checkbox for the row called TITLE</p>
  
  <p>I can get to the TITLE with the following XPATH.  </p>
  
  <pre><code>//span [text()="TITLE"]
  </code></pre>
  
  <p>My code snippet is:</p>
  
  <pre><code>        def add_mapping2(self, name):
      try:
          checkbox = self.driver.find_element(By.XPATH, '//span [text()="+name+"]/../../preceding-sibling::td/div/input[@type="checkbox"]') 
          checkbox.click()
      except NoSuchElementException, e:
          return False
      return True
  </code></pre>
  
  <p>From my unittest.Testcase class I call the method as follows:</p>
  
  <pre><code>class MappingsPage_TestCase(BaseTestCase):
  
      def test_add_mappings(self):
          mappingsPage = projectNavigator.select_projectNavigator_item("Mappings")
          mappingsPage.add_mapping2("TITLE")
          mappingsPage.add_mapping2("SNAME")
  </code></pre>
  
  <p>The HTML is:</p>
  
  <pre><code> &lt;table id="data_configuration_edit_mapping_tab_mappings_ct_mapping_body" cellspacing="0" style="table-layout: fixed; width: 100%;"&gt;
  &lt;colgroup&gt;
  &lt;tbody&gt;
      &lt;tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="0"&gt;
      &lt;tr class="GOFU2OVEH GOFU2OVGH GOFU2OVPG GOFU2OVMG" __gwt_subrow="0" __gwt_row="1"&gt;
          &lt;td class="GOFU2OVEG GOFU2OVFH GOFU2OVHG GOFU2OVHH GOFU2OVAH GOFU2OVNG"&gt;
          &lt;td class="GOFU2OVEG GOFU2OVFH GOFU2OVHH GOFU2OVAH GOFU2OVNG"&gt;
              &lt;div __gwt_cell="cell-gwt-uid-792" style="outline-style:none;"&gt;
                  &lt;span title="TITLE" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"&gt;TITLE&lt;/span&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td class="GOFU2OVEG GOFU2OVFH GOFU2OVHH GOFU2OVBH GOFU2OVOG GOFU2OVAH GOFU2OVNG"&gt;
              &lt;div __gwt_cell="cell-gwt-uid-793" style="outline-style:none;" tabindex="0"&gt;
                  &lt;input type="checkbox" checked="" tabindex="-1"/&gt;
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="2"&gt;
          &lt;td class="GOFU2OVEG GOFU2OVGG GOFU2OVHG"&gt;
              &lt;div __gwt_cell="cell-gwt-uid-791" style="outline-style:none;"&gt;
                  &lt;input type="radio" name="rbCrossRow124"/&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td class="GOFU2OVEG GOFU2OVGG"&gt;
              &lt;div __gwt_cell="cell-gwt-uid-792" style="outline-style:none;"&gt;
                  &lt;span class="" title="FNAME" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"&gt;FNAME&lt;/span&gt;
              &lt;/div&gt;
          &lt;/td&gt;
          &lt;td class="GOFU2OVEG GOFU2OVGG GOFU2OVBH"&gt;
              &lt;div __gwt_cell="cell-gwt-uid-793" style="outline-style:none;"&gt;
                  &lt;input type="checkbox" tabindex="-1"/&gt;
              &lt;/div&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr class="GOFU2OVEH" __gwt_subrow="0" __gwt_row="3"&gt;
      &lt;tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="4"&gt;
      &lt;tr class="GOFU2OVEH" __gwt_subrow="0" __gwt_row="5"&gt;
      &lt;tr class="GOFU2OVFG" __gwt_subrow="0" __gwt_row="6"&gt;
      more rows with names with checkboxes etc......
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>What XPATH could I use to get the checkbox for TITLE, FNAME etc?
  I have the table ID "data_configuration_edit_mapping_tab_mappings_ct_mapping_body"
  Maybe there is a way to start from the table ID and use a for loop to iterate through the rows and find the particular checkbox?</p>
  
  <p>Thanks.</p>
  
  <p>Riaz</p>