John,

I believe the .tables method returns an array of all the tables within
div, so .tables[0] will return the first table in the div.

Try:

mainFrame.div(:id, "menuId").tables[1].click

Ethan

On 3/15/07, John Lloyd-Jones <[EMAIL PROTECTED]> wrote:
> I have a tricky page where I need to click on a a menu that has been
> implemented as a table. There are many such menus and I can find the
> surrounding div (by id), but there is no other way to find the table (it
> doesn't have a predictable index, for example). So what I want is to ask the
> Div for the table -- where it is in fact, the only nested table).
>
> E.g.
>
> menu = mainFrame.div(:id, "menuId")
> menuTable = menu.table(:index, 1)
> menuTable[ 4 ][ 1 ].click
>
>
> Alas, this doesn't work out of the box -- Watir assumes that you always want
> to find tables nested in the document, so it errors out on menu.table()
> saying that there is no document. As tables are commonly nested in divs, and
> as far as I can see, adding a table method to the Div class wouldn't break
> any current code, is there any reason why Div couldn't do something like
> this?
>
> class Watir::Div
>    def table( how, what )
>       if how == :index
>          @o.getElementsByTagName( 'table' )[what.to_s]
>          Table.new(@ieController, :from_object, table)
>       else
>           super.table( how, what )
>       end
>    end
> end
>
> The table method overrides the super class for :index, but not for :id
> (which should be unique, so it doesn't need special handling).
> It certainly does make the code snipped abpve work. I haven't done any
> exhaustive tests to see if it breaks anything, but I can't think of any
> scenario where it could.
>
> John
>
>
> _______________________________________________
> 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