Ruby Version: 1.8.7
WATIR Version: 2.0.1
OS: Win 7
So I came across this issue as I just upgraded to 2.0.1. Basically,
when i get a TableRow object using the [] method, and then try to get
the text value from it, it always returns the text of the row with
index of zero.
Steps to reproduce:
1) HTML
<html>
<table id="a_table">
<tr><td>boring text</tr></td>
<tr><td>great text</td></tr>
<tr><td>the best text ever<td></tr>
</table>
</html>
2) Code
#------------------------
require 'rubygems'
gem 'watir', '=2.0.1'
require 'watir'
b = Watir::IE.new
b.goto 'http://localhost/test.html'
#get the third table row with text 'the best text ever'
table = b.table(:id, 'a_table')
row = table.rows[2]
#the TableRow object has the correct ole_object stored within it
#before we call row.text
puts row.ole_object.invoke('innerHTML')
#trying to get the text unfortunately outputs the text from row 0:
'boring text'
puts row.text
#now the TableRow object has the wrong ole_object in it
puts row.ole_object.invoke('innerHTML')
#it looks like this happens because our TableRow object is using an
index of zero and not two
puts row.inspect
#------------------------
3) Summary
So, I read through some of the code, and it looks like this is
happening because when we call
table.row[2], our each method in elements_collection.rb doesn't pass
on any index information to
tagged_element_locator in container.rb. So, when we call set_specifier
inside tagged_element_locator, we set a
default value to an index of zero. Later on when we call row.text,
it's locate method thinks we are looking
for the row with an index of zero and not two. It then sets our
ole_object in the TableRow object to the zero index value.
Brett
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]