# Error on iterating through a set of nested tables in a form

**URL:** <https://www.ruby-forum.com/t/error-on-iterating-through-a-set-of-nested-tables-in-a-form/184138>\
**Category:** Ruby\
**Created:** [February 25, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/error-on-iterating-through-a-set-of-nested-tables-in-a-form/184138 "2010-02-25T16:54:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arti\_singh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ba9def/32.png) [@arti\_singh](https://www.ruby-forum.com/u/arti_singh)\
**Post date:** [February 25, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/error-on-iterating-through-a-set-of-nested-tables-in-a-form/184138/1 "2010-02-25T16:54:27Z")

</div>

I am trying to run the code below on a nested table that is embedded in  
a form, but I keep getting the error:

Undefined method: table for NIL class when I try to iterate through this  
table.  
is there anything that I am missing here.

Should I have accessed the tables in the context of the forms?

$forms=Watir::IE.new  
formdatatypes=[TimeStr(),"#{rand(1000).to\_s}",“Hello World”]

prelimtable=$forms.table(:index,1).cell(:id,‘Data’).div(:id,/Container/)

prelimtable.tables(:class,‘Layout’).each do |t| # since you don’t have  
ID’s, look at every table  
for i in 1…t.row\_count# for every row in this table  
t[i].each do |cell|# for every column in this row, look at its  
contents  
if cell.text\_field(:id, /Text/).exists? # if true, this is your  
cell  
cell.text\_field(:id, /Text/).value=formdatatypes[2]  
elsif cell.text\_field(:id, /Date/).exists?  
cell.text\_field(:id, /Date/).value=formdatatypes[0]  
elsif cell.text\_field(:id, /Numeric/).exists?  
cell.text\_field(:id, /Numeric/).value=formdatatypes[1]  
elsif cell.checkbox(:id,/Text/).exists?  
cell.checkbox(:id,/Text/).set  
elsif cell.checkbox(:id,/Date/).exists?  
cell.checkbox(:id,/Date/).set  
elsif cell.checkbox(:id,/Numeric/).exists?  
cell.checkbox(:id,/Numeric/).set  
elsif cell.radio(:id,/Text/).exists?  
cell.radio(:id,/Text/).set  
elsif cell.radio(:id,/Date/).exists?  
cell.radio(:id,/Date/).set  
elsif cell.radio(:id,/Numeric/).exists?  
cell.radio(:id,/Numeric/).set  
elsif cell.select(:id,/Text/).exists?  
selecttext=cell.select(:id,/Text/).getAllContents()  
cell.select(:id,/Text/).set(selecttext[rand(selecttext.length)])  
elsif cell.select(:id,/Date/).exists?  
selecttext=cell.select(:id,/Date/).getAllContents()  
cell.select(:id,/Date/).set(selecttext[rand(selecttext.length)])  
elsif cell.select(:id,/Numeric/).exists?  
selecttext=cell.select(:id,/Numeric/).getAllContents()  
cell.select(:id,/Numeric/).set(selecttext[rand(selecttext.length)])  
end  
end  
end  
end
