Unfortunately I think that table.each still uses the old row_count method. If
your problem is that the each itterator tries to access a non existent table
row, the easiest way to get around this is to rescue the exception. See below:
...paste this html into an html file named tmp.html and open it in IE
<html>
<head></head>
<body>
<table>
<tr><td>top</td><td>1</td></tr>
<tr><td>top</td><td>2</td></tr>
<tr>
<td>top</td>
<td>
<table>
<tr><td>nested</td><td>1</td></tr>
<tr><td>nested</td><td>2</td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>
...paste this into a .rb file and run it
require 'watir'
br = Watir::IE.attach(:url, /tmp/)
mytable = br.table(:index, 1)
# this returns 5
puts mytable.row_count
# this returns 3
puts mytable.row_count_excluding_nested_tables
# this will not work without rescue since it uses row_count instead of
# row_count_excluding_nested_tables, comment out the begin, rescue block
# and you will most likely see the error you are experiencing
begin
mytable.each do |row|
puts row.text.to_s
end
rescue WIN32OLERuntimeError
puts "went past the end of the table"
end
If you have more specific problems maybe you could show us your code.
I'm not sure why this still behaves this way. I can't think of a situation
where table.each using row_count would be useful to me. Maybe I have a lack of
imagination this morning. :) Can somebody else think of a reason it needs to
be this way?
Alan
[X]
From: [email protected] [mailto:[email protected]] On
Behalf Of Shaik Mohammed Firoz
Sent: Wednesday, April 15, 2009 4:18 AM
To: [email protected]
Subject: [wtr-general] Problem when iterate through the table
table = $ie.table(:id, "ctl00_ContentPlaceHolder1_tableDetails")
gvrowcount = table.row_count_excluding_nested_tables
>From above statement i got the row count of table excluding nested tables
>using the method "table.row_count_excluding_nested_tables" .
but when tried to iterate through the table using FOR loop, it is iterating
through nested tables also.
I am failed to find the method where I can iterate through table excluding
nested tables.
Thanks,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To post to this group, send email to [email protected]
Before posting, please read the following guidelines:
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---