History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: WTR-26
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Charley Baker
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Watir

Table.row_count returns number of all TR elements, including rows from nested tables

Created: 27/Apr/06 01:52 PM   Updated: 24/Oct/08 12:43 PM
Component/s: HTML Controls
Affects Version/s: 1.4.1
Fix Version/s: 1.6.0

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown


 Description  « Hide
Current row_count implementation (Watir 1.3.1) returns number of all TR elements in the table:

return @o.getElementsByTagName("TR").length

which effectively returns all rows in the table (including nested tables).

I think it should return number of rows for the top level table only.
Following implementation worked for me:

def row_count
        raise UnknownTableException , "Unable to locate a table using #{@how} and #{@what} " if @o == nil
        return @o.rows.length
    end

 All   Comments   Work Log   Change History      Sort Order:

Bret Pettichord - 19/Sep/06 10:50 PM
Proposed solution looks right.

However, we really should do this in conjuction with also providing child_rows (and child_cells) which would have a number of rows corresponding to this count.

Indeed once this were done, we arguably should deprecate row_count in favor of the child_rows.count, which is more rubyish.

Joe DiMauro - 19/May/08 03:57 PM
Brett,

As I'd discussed with you I'm seeing a poblem with a method that reads text from a table. It loops through the rows in a table, and then moves on to the next table untilthe matching text is found.
 
while(iRowIndex <= $ie.table(:index, iTableIndex).row_count)
  aRowText = ($ie.table(:index, iTableIndex).row_values(iRowIndex))
end

In each case I investigated when this method fails the page contains nested tables, and the error occurred when trying to read text from a row of the table that contains a nested table. Sadly the practice of nesting tables is pretty common, some pages I've looked at have 8-levels of nests (not exactly W3.org compliant)
 
The error when using the row_values method to read the text from the table's row when that table contains a nested table is:
E, [19-May-2008 11:39:25#180] ERROR -- : Error and Backtrace: unknown property or method `1'
    HRESULT error code:0x80020006
      Unknown name.
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1230/./watir.rb:3274:in `[]'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1230/./watir.rb:3274:in `row'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1230/./watir.rb:3236:in `column_count'
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1230/./watir.rb:3292:in `row_values'
 
I was able to pair down an example to only three tables on the page. Each time the method errors is when that table contains a nested table. For example:
  Table 1 has 1 Row, and 1 Column, and contains a nested table (Table 2) in that column
  Table 2 also has 1 Row and 1 Column, and contains a third nested table (Table 3).
  Table 3 has 2 rows, (each with 1 column apiece).
 
So when it loops to read the text from the rows of the inner most nested table (Table 3) it works fine, But when looping through the rows in Table 2 the error occurs once a on-existent row is reached. I had the code display the number of rows in Table 2 using row_count, and it was incorrectly reporting more rows that it directly contains (presumably its counting its own row along with the rows from the nested table)
 

Nathan - 24/Oct/08 10:53 AM
I don't think that we should fix this issue, because it does not rely on web standards. A work around has already been supplied, and I believe that should be sufficient -- we can place that in the wiki for people who DO need to test web pages with nested tables. Please reference http://groups.google.com/group/watir-general/browse_thread/thread/367af314e9c1d017 for more information. I ran a simple W3C validation test on a small XHTML transitional file both containing nested tables and without nested tables, and the one without nested tables validated successfully on W3C's HTML validator, whereas the one WITH nested tables was invalid according to W3C's validator. I don't see a way to vote against this, but if it isn't supported by web standards, I don't thing that we should pursue it strongly. That isn't only my opinion. More references: http://veerle.duoh.com/blog/comments/starting_with_css_and_bug_fixing_tips/ and http://alistapart.com/articles/tohell/

Bret Pettichord - 24/Oct/08 12:43 PM
Added new method row_count_excluding_nested_tables to Watir::Table. This will be included in Watir 1.6.