Issue 1 - Checking row class
You are passing tr
parameters, which is why Ruby thinks it is a method. In this case, tr
is actually an element that is selected for the current iteration of the loop. To check the current tr's class attribute, the elsif
statement should be:
elsif tr.class_name == "subjectField"
Issue 2 - Iterating rows
Note that you will also have a problem with the line:
@f.div(:id => 'household').table(:class => 'color_table').tbody.trs.find
The find
method will iterate through the trs until the block evaluates as true. Since the block will always evaluate to true or break, you will only get 0 or 1 subjects. Use each
instead:
@f.div(:id => 'household').table(:class => 'color_table').tbody.trs.each
Putting it together
Putting the above fixes together, the method could be written as:
def countRows
@subjects = 0
table = @f.div(:id => 'household').table(:class => 'color_table')
table.tbody.trs.each do |tr|
break if tr.td(:class => "separator").exists? == true
@subjects += 1 if tr.class_name == "subjectField"
end
@subjects
end