title: How to count table rows using class name in Watir?
body: <p>I want to count all table rows which class name is <code>subjectField</code> and to stop counting if some row's class name is <code>separator</code>.</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div id="household" class="block"&gt;
  
  &lt;div class="block_title"&gt; … &lt;/div&gt;
  &lt;table class="color_table"&gt;
      &lt;thead&gt; … &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr class="first_row"&gt; … &lt;/tr&gt;
          &lt;tr class="subjectField" style="display:none"&gt; … &lt;/tr&gt;
          &lt;tr class="odd_row"&gt; … &lt;/tr&gt;
          &lt;tr class="subjectField" style="display:none"&gt; … &lt;/tr&gt;
          &lt;tr class="even_row"&gt; … &lt;/tr&gt;
          &lt;tr class="subjectField" style="display:none"&gt; … &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class="separator" rowspan="1" colspan="10"&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr class="even_row"&gt; … &lt;/tr&gt;
          &lt;tr class="subjectField" style="display:none"&gt; … &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My code: </p>
  
  <pre><code>def countRows
      @subjects = 0
      @f.div(:id =&gt; 'household').table(:class =&gt; 'color_table').tbody.trs.find do |tr|            
      if tr.td(:class =&gt; "separator").exists? == true
          break
      elsif tr(:class =&gt; "subjectField").exists? == true
          @subjects = @subjects + 1
      end         
  end
  return subjects
  end
  </code></pre>
  
  <p>This does not work for me. It says that <code>tr</code> on <strong>line 6</strong> is <em>undefined method</em>.</p>
  
  <p>Does anybody know how to solve this problem?</p>