Home > watir > watir table().row_values as array indices

watir table().row_values as array indices

Using 'table.row_values(2) I would like to get array as a result.

for example, given a table of

<table>
 <tbody>
  <tr>
   <td>Name</td>
   <td></td>
  </tr>
  <tr>
   <td>value</td>
   <td>Select List (Item1, Item2, Item3)</td>
 </tr>
</table>

I would like

ie.table(:index, 1).row_values(2)

to return an array of element value per indices, like so:

["Name", "\r\n", "value", " - Select - Item1, Item2, Item3"]

Then I could do something like:

ie.table(:index, 1).row_values(2)[1]

to get

'value'

currently the result is returned as an one element array. Which is not helpful for matching a specific value to a specific row.
i.e.

["Name: \r\nInformatique \r\n - Select - Item1, Item2, Item3"]

In order to test specific rows for specific values I have been using something such as:

ie.table(:index, 1).row_values(2).to_s.split(/\r\n/)[1].match("value")

=> # (Note, the above code is all untested, just an example of the top of my head)

----------------------------------------------------------

EDIT: I need to amend the above post which is incorrect.

The behavior I expect is the behavior provided, the key is making sure you
specify the correct table ;) If you do, the results are returned as array elements.

If you specify an index of a parent table by mistake, then row values are returned as an array as expected,
but will include any nested tables row values in the content.

Hopefully, this example, which is tested, will demonstrate what I mean.

<table border=1>
 <tbody>
  <tr>
   <td>
   Contacts
    <table>
     <tbody>
      <tr>
       <td>
        <table border=1>
         <tbody>
          <tr>
           <td>First</td>
           <td>Last</td>
           <td>Addr1</td>
           <td>City</td>
          </tr>
          <tr>
           <td>Billy</td>
           <td>McLilly</td>
           <td>123 Street</td>
           <td>My Town</td>
         </tr>
          <tr>
           <td>Jan</td>
           <td>Smith</td>
           <td>456 B Street</td>
           <td>Your Town</td>
         </tr>
        </table>
        </td>
        </tr>
    </table>
    </td>
    </tr>
    </table>
irb(main):067:0> ie.table(:index, 1).row_values(1)
=> ["Contacts FirstLastAddr1City\r\nBillyMcLilly123 StreetMy Town\r\nJanSmith456
 B StreetYour Town"]
irb(main):068:0> ie.table(:index, 2).row_values(1)
=> ["FirstLastAddr1City\r\nBillyMcLilly123 StreetMy Town\r\nJanSmith456 B Street
Your Town"]
irb(main):069:0> ie.table(:index, 3).row_values(1)
=> ["First", "Last", "Addr1", "City"]
irb(main):070:0> ie.table(:index, 3).row_values(2)
=> ["Billy", "McLilly", "123 Street", "My Town"]
irb(main):071:0> ie.table(:index, 3).row_values(3)
=> ["Jan", "Smith", "456 B Street", "Your Town"]
irb(main):073:0> ie.table(:index, 3).row_values(2)[0]

=> "Billy"
Categories: watir Tags:
  1. No comments yet.