Forum: Ruby Retrieves the count for the list of entries - not working

Posted by Syed H. (syed_h)
on 2013-03-15 17:03
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
Posted by tamouse mailing lists (Guest)
on 2013-03-15 17:25
(Received via mailing list)
On Fri, Mar 15, 2013 at 11:04 AM, Syed H. <lists@ruby-forum.com> 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?
Posted by Syed H. (syed_h)
on 2013-03-15 17:43
Ideally i would not want that to be sent out but we have been asked to 
send out a message.
Posted by tamouse mailing lists (Guest)
on 2013-03-15 17:59
(Received via mailing list)
On Fri, Mar 15, 2013 at 11:43 AM, Syed H. <lists@ruby-forum.com> 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
Posted by tamouse mailing lists (Guest)
on 2013-03-15 18:09
(Received via mailing list)
On Fri, Mar 15, 2013 at 11:04 AM, Syed H. <lists@ruby-forum.com> 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
Posted by Syed H. (syed_h)
on 2013-03-15 18:28
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.