Ticket entered: http://jira.openqa.org/browse/WTR-149

Ian's point about 0-indexing vs. 1-indexing is noted in the ticket.
Perhaps this should only be a candidate for inclusion in Watir 1.6?

Ethan

On 5/8/07, Ian Webb <[EMAIL PROTECTED]> wrote:
> This worked great! I only had to make a couple of minor corrections.
>
> First off, each_with_index starts counting at 0, while Watir starts
> counting as 1. So I had to do rows_to_click << (i+1). And when iterating
> back through the table to actually click the links, I had to add ie.wait
> to that loop to keep it from trying to click the link as soon as the
> child window closed, before IE had even had a chance to render the
> reloaded page!
>
> In any case, it's working now, and I learned quite a bit. I agree that
> the each_with_index should be included - although I'm not sure what the
> preferred index behaviour should be. Perhaps that's why it's not in
> there now?
>
> Thanks again,
> Ian
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Ethan Jewett
> Sent: Tuesday, May 08, 2007 9:18 AM
> To: [email protected]
> Subject: Re: [Wtr-general] Using an ie.table.each do |row| loop when
> thepagein the ie window refreshes itself
>
> Ian,
>
> Sorry about the "rows" and "each_with_index" issues.  Hopefully
> that'll teach me to test suggestions : )
>
> table(:index,29) clearly does the same thing I thought
> table(:index,29).rows does.
>
> As for the "each_with_index", if you just mixin the Enumerable module
> to the Watir::Table class like this:
>
> class Watir::Table
>   include Enumerable
> end
>
> before you use "each_with_index", then you should be in good shape.
> This seems like something that should be added to the base Watir,
> since rows in a table are generally an enumerable element and the
> current Watir::Table.each method returns the rows of the table in
> order.
>
> Any objections?  If not, I'll open a ticket.
>
> Ethan
>
> On 5/7/07, Ian Webb <[EMAIL PROTECTED]> wrote:
> > Thanks - this does look like a good approach. The table's layout
> doesn't
> > change, it just reloads to update the data within the table with the
> > entries that were just made in the popup window. It's a really
> annoying
> > UI, especially when you have test cases that require changing a dozen
> > rows and therefore opening the popup a dozen times.. hence why I'm
> quite
> > eager to get Watir doing it instead.
> >
> > However, each_with_index appears to be an undefined method for
> ie.table
> > objects. I can iterate on .each just fine, but .each_with_index is
> > undefined. (.rows is undefined as well; .each works fine if I leave it
> > out)
> >
> > I'm wondering if maybe there's a way to store the indices of the
> buttons
> > it's going to click on within the array, rather than the rows
> > themselves. I tried buttons_to_click << row[5].link(:index,1), but
> that
> > doesn't work.
> >
> > Thanks,
> > Ian
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Ethan Jewett
> > Sent: Saturday, May 05, 2007 6:55 PM
> > To: [email protected]
> > Subject: Re: [Wtr-general] Using an ie.table.each do |row| loop when
> > thepage in the ie window refreshes itself
> >
> > Ian,
> >
> > Reloading probably invalidates the table object, resulting in your
> > "Access denied" error when ruby goes back for the next row in the
> > table.
> >
> > Suggestion:  Assuming that submitting and reloading doesn't affect the
> > table layout, use rows.each_with_index to build an array of indices of
> > relevant rows.  Then cycle through the array clicking and submitting.
> > For instance (untested, unfortunately):
> >
> > rows_to_click = Array.new
> >
> > ie.table(:index, 29).rows.each_with_index do |row, i|
> >   rows_to_click << i if (row[1].text =~ /#{journals}/) != nil
> > end
> >
> > rows_to_click.each do |i|
> >   [Do the clicking and such for row i here.]
> > end
> >
> > This could be made substantially prettier, but hopefully it gets the
> job
> > done.
> >
> > Ethan
> >
> > On 5/4/07, Ian Webb <[EMAIL PROTECTED]> wrote:
> > > Here's the code snippet that's giving me problems:
> > >
> > >   ie.table(:index,29).each do |row|
> > >     if (row[1].text =~ /#{journals}/) != nil then #If there is a
> match
> > > for that regex
> > >       row[5].link(:index,1).click # this makes the popup window
> appear
> > >       cw = Watir::IE.attach(:title,'Popup Window') # attach to the
> > popup
> > > window
> > >       doRolesPopup(cw) # fill out and submit the form
> > >     end
> > >   end
> > >
> > > doRolesPopup fills out a form in the cw page, then clicks submit.
> The
> > > submit button submits the form, then closes the cw window and
> reloads
> > > the ie window. This reload of the page referenced by the ie object
> > > appears to break the row object, since I get the following error:
> > >
> > > c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:2461:in `invoke': unknown
> > > property or method `rows' (WIN32OLERuntimeError)
> > >     HRESULT error code:0x80070005
> > >       Access is denied. from
> > > c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:2461:in `row'
> > >         from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:2404:in `each'
> > >         from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:2404:in `upto'
> > >         from c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:2404:in `each'
> > >         from assignroles.rb:51
> > >         from c:/ruby/lib/ruby/1.8/csv.rb:532:in `parse'
> > >         from c:/ruby/lib/ruby/1.8/csv.rb:560:in `each'
> > >         from c:/ruby/lib/ruby/1.8/csv.rb:531:in `parse'
> > >         from assignroles.rb:35
> > >
> > > Is there any way to keep this simple .each loop, or do I need to
> work
> > > around it?
> > >
> > > Thanks,
> > > Ian
> > > _______________________________________________
> > > Wtr-general mailing list
> > > [email protected]
> > > http://rubyforge.org/mailman/listinfo/wtr-general
> > >
> > _______________________________________________
> > Wtr-general mailing list
> > [email protected]
> > http://rubyforge.org/mailman/listinfo/wtr-general
> > _______________________________________________
> > Wtr-general mailing list
> > [email protected]
> > http://rubyforge.org/mailman/listinfo/wtr-general
> >
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to