Retrieves the count for the list of entries - not working

def get_entry_count(type)
controls = (type.nil?)? nil : get_list_entries_container(type)
retVal = 0
unless (controls.nil?)
retVal = controls.length
else
retVal = puts “Unable to find list entries for table of:
#{type}”
end
return retVal
end

Using gems 1.9.1 on Ruby 1.9.2 and watir-classic-3.3.0

I am unable to retrieve the list of entries from the column and get an
error

Uncaught exception: undefined method `length’ for
#Watir::TableRow:0x14b2348

I think it lies under the get_entry_count but not quite sure, It worked
with Ruby 1.8.7

On Fri, Mar 15, 2013 at 11:04 AM, Syed H. [email protected] wrote:

def get_entry_count(type)
controls = (type.nil?)? nil : get_list_entries_container(type)

This is probably the source of your error ^^ what is being returned by
get_list_entries_container(type) may not be nil, but apparently the
class Watir::TableRow does not respond to the .length method.

  retVal = 0
  unless (controls.nil?)
     retVal = controls.length
  else
     retVal = puts "Unable to find list entries for table of:

#{type}"

This seems suspicious (though unrelated to your problem). The return
value of puts is nil. Are you sure you want to actually send that to
output at that point?

Ideally i would not want that to be sent out but we have been asked to
send out a message.

On Fri, Mar 15, 2013 at 11:04 AM, Syed H. [email protected] wrote:

end
Aslo, Syed, I hope you don’t mind, I’d like to offer something a
little cleaner? You can surely reject this if you want… You may not
like early returns, which it seems your code is going out of it’s way
to avoid. I think they make clearer code in some cases.

def get_entry_count(type)
return if type.nil? # you /might/ consider raising an exception if
this isn’t supposed to happen?
controls = get_list_entries_container(type)
return controls.cells.count unless controls.nil?
puts “Unable to find list entries for table of type #{type}”
0
end

On Fri, Mar 15, 2013 at 11:43 AM, Syed H. [email protected] wrote:

Ideally i would not want that to be sent out but we have been asked to
send out a message.

Ok, send out the message, but return something more meaningful in that
context?

Also, on the Watir::TableRow.length problem – to get the count of
elements in the row, given test contains the row, try:

test.cells.count

I dont mind at all I am still learning ruby and I appreciate your help
and will take the suggestion as it does look cleaner. the scenario for
this test is it goes to a certain page and tries to see if there is
something in the column if not then it moves on to adding profile. In
this case there is nothing in the table but still have to check and see
if there is something.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs