title: how to dynamically read a specific cell value in a table using selenium and python
body: <p>I am working on a automation script [using selenium and python] that should do the following</p>
  
  <ol>
  <li>Read the table rows and columns dynamically, look for column[this is constant) which has 0 value set in any of the rows and if found click the [assign/unassign] button column in the same row</li>
  </ol>
  
  <p>I do not want to hard-code the xpath of the column that has value "0" rather look for it dynamically and proceed .</p>
  
  <p>Below code is what i have written </p>
  
  <pre><code>trows = table1.find_elements_by_xpath("//table[@id='ambassadors-for-assignment']/tbody/tr")
  row_count = len(trows)
  tcols = trows.find_elements_by_xpath("//table[@id='ambassadors-for-assignment']/tbody/tr/td")
  col_count = len(tcols)
  first_part = "//table[@id=ambassadors-for-assignment']/tbody/tr["
  second_part = "]/td["
  third_part = "]"
  for i in range(1, len(row_count)):
      for j in range(1, len(col_count)):
            final_xpath = first_part+i+second_part+j+third_part      
  </code></pre>
  
  <p>HTML file structure</p>
  
  <pre><code>&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt; james &lt;/td&gt;
      &lt;td&gt; watson &lt;/td&gt;
      &lt;td&gt; 10 | 5 &lt;/td&gt;
      &lt;td&gt;
        &lt;div class="btn-group" role="group"&gt;
           &lt;button class="btn btn-success" type="button"&gt;
               &lt;i class="fa fa-plus"&gt;&lt;/i&gt;
           &lt;/button&gt;
          &lt;button class="btn btn-danger" type="button"&gt;
              &lt;i class="fa fa-minus"&gt;&lt;/i&gt;
          &lt;/button&gt;
        &lt;/div&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  ....
  </code></pre>
  
  <p>My HTML file has n number of rows with columns as given above. As i mentioned , i would like to read the third column value[i.e 10 | 5] to see whether or not its 0 [consider only the first item in the third column] and then click the button[btn btn-success] in the next column.</p>
  
  <p>Any pointers to proceed further would be appreciated!</p>
  
  <p>I will provide the link to actual HTML file in the comments section </p>