Here is an example of my solution.  The scenario is there are multiple tables with various buttons (all the button have the same name—‘Deactivate’).  The test find table at index 8 and clicks the button in the last row in column 2.  At that point the page has to be reloaded in order to account for the change in the page and then check

 

    def test4_DeactivateGEMS

      gotoTestPage()

 

      # Find the link and click it

      $ie.link(:text, /GEMS/i).click

     

      # Load my target table 

      table = $ie.table(:index, 8)

     

      # get the number of rows 

      rowCount = table.row_count

           

      # remove the button in column 2 in the last row 

      table[rowCount][2].button("Delete").click

           

      # reload the table variable because the page has changed 

      table = $ie.table(:index, 8)

             

      begin

          assert_not_equal(rowCount,table.row_count)

      rescue => e

          puts "*FAILED*." + e.message + "\n" + e.backtrace.join("\n")

      end

     $ie.close

   end

 

If there is nothing at index [1] [1] then do the view source, find your table and count the <tr> tags until you get the a row with data and start there.  You could iterate over the rows and columns if you need move flexibility.

Also, I would use a regular _expression_ to find the text e.g. /test to search for/i (use the ‘i’ if case doesn’t matter).

 

Have you checked out the table_test.rb in the untitest folder of your WATIR installation directory?

 

--Mark


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Amitha Shetty
Sent: Monday, October 17, 2005 11:12 PM
To: [email protected]
Subject: Re: [Wtr-general] How to check if a particular row exists in atable?

 

  I checked again. I am accessing the right table.

But as u can see from the HTML below, first two rows of the table are empty.

So when I try to acess the first row,its throwing an exception.The tables are dynamic and based on user input.

I want to test if the input added has been saved. So I want to iterate through the table until I find the text.

 

HTML of the table:

<table align="center" border="0" cellpadding="0" cellspacing="0" width="200%">
                                                                <tr>
                                                                </tr>
                                                                <tr>
                                                                </tr>
                                                                <tr>
                                                                    <td align="left" bgcolor="#FFFFFF" title=""><img alt="normal" border="0" height="9" src="" width="8">&nbsp;&nbsp;<a href="" height=500, scrollbars=yes')">ITEM 1</a></td>
                                                                </tr>
                                                                <tr>
                                                                </tr>
                                                                <tr>
                                                                </tr>
                                                                <tr>

amol deshpande <[EMAIL PROTECTED]> wrote:

Hi,
try using the getContents to find the text.
var = table[1][1].getContents
puts var

As far not finding the cell means (normally)that you
are accessing the wrong table with wrong arguments.
A long way to get around is to try each table index
and then locate what you are looking for.
hope this helps.
AD

--- Amitha Shetty <[EMAIL PROTECTED]>wrote:

> Dynamic tables are hidden and shown when a
> particular item is added to the pane.
> I got the table index and also the table has 9 rows
> and 1 column.
> When I try to access table[1][1](and search for a
> text there), It throws the following exception:
> c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:2606:in
> > `[]': Unable to locate a cell at index 1
> > (Watir::Exception::UnknownCellException).
> >
> What I w! ant to do is look for the text in the row
> only if that row exists.But exists? function did not
> work for a row...How else can I do it?
>
> "Cain, Mark" <[EMAIL PROTECTED]>wrote:
> v\:* {behavior:url(#default#VML);}o\:*
> {behavior:url(#default#VML);}w\:*
> {behavior:url(#default#VML);}.shape
>
{behavior:url(#default#VML);}st1\:*{behavior:url(#default#ieooui)
> }
> What I had to do was do a view source on the page
> and find the desired table using IE’s find function
> (searched for
> page I would count the number of tables (using find
> next) until I got to the desired table—the count
> number being the index of that table (I believe
> tables are zero based indexes so keep that in mind).
> Once there I could do any number of things to that
> table.
>
>
>
> Are the dynamic tables already in the page hidden
! > and shown or are they added based on user input?
>
>
>
> --Mark
>
>
> ---------------------------------
>
>
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Amitha Shetty
> Sent: Monday, October 17, 2005 12:34 AM
> To: [email protected]
> Subject: [Wtr-general] How to check if a particular
> row exists in a table?
>
>
>
>
>
>
>
>
> Hi,
>
>
> How to check if a particular row exists in a
> table?
>
>
>
> There are more than one table in the screen to use
>
>
> $ie.row(:id, 'row1').exists?.
>
>
> Also there are tables within a table and also
> tables are dynamic.
>
>
> When I try table[x][y].exists? I get an error which
> says:
> !
>
> c:/ruby/lib/ruby/site_ruby/1.8/watir.rb:2606:in
> `[]': Unable to locate a cell at index 1
> (Watir::Exception::UnknownCellException).
>
>
>
>
>
> How do I test this?
>
>
>
>
>
> Thanks,
>
>
> Amitha
>
>
>
>
>
> ---------------------------------
>
>
> Yahoo! India Matrimony: Find your partner now.
>
>
> ---------------------------------
>
>
> Yahoo! India Matrimony: Find your partner now.
>
> _______________________________________________
> Wtr-general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>
>
> ---------------------------------
> Yahoo! India Matrimony: Find your partner now.>
_______________________________________________
> Wtr-! general mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/wtr-general
>


No Body Has ever Collided With The Sky...So Sky Is The Limit!



__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general


Yahoo! India Matrimony: Find your partner now.

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to