I have the following code which is supposed to get me only the new events added to the table from the last time i checked the table.
events=@browser.table( :id =>'table_events').tbody.rows
....
some code
....
events_new=@browser.table( :id =>'table_events').tbody.rows
events=events_new - events # not working !!
Im getting the fallowing error :
undefined method `-' for #<Watir::TableRowCollection:0x007fccb9ba2358> (NoMethodError)
I understand that the “-” predicate is wrong of course, but is there a method that does what i need or do i need to go over all the TableRowCollection and find the new rows manually?
You could try converting the
TableRowCollectionto an array, which does support subtraction:That will work provided the elements have a useful
==method defined – and it looks like they do.Correction: actually, because array subtraction is implemented using a hash table for efficiency (view source here if you’re curious), it is not the
TableRow#==method that is important but theTableRow#hashmethod. Fortunately, it looks like Watir implements that as well.