Watir: Need help in defining a dynamic array

Hi,

I am new to ruby and hence need some help in defining a dynamic array.
What I need to do is this:

1. I have 5 browsers open in my desktop.
2. I want to assign them browser id's 1,2,3,4,5 (should be dynamic,
since 5 browsers, so using 5 browser id's). 1 way I thought was to use
the window handle (hwnd) for each of the open browser.
3. So I used hwnd method and am storing it like @browserID = ie.hwnd.
But I want the browserID to be a dynamic array which would increment
everytime a new browser is open and will store the value of its window
handle.

Can anyone help me create a dynamic array and store the hwnd to it as
and when a browser is open? Even if you can help me with the basics of
using a dynamic array, I would be satisfied.

Thanks,
Anukul

···

--
Posted via http://www.ruby-forum.com/.

# Can anyone help me create a dynamic array and store the hwnd to it as
# and when a browser is open? Even if you can help me with the basics of
# using a dynamic array, I would be satisfied.

ruby arrays are dynamic.

ff is a simple example. it just automatically stores 5 watir instances in the array. fr then on, you can access each instance or browser by just referencing the array...

a=[]
#=> []

5.times do
  a << Watir::IE.new
end
#=> 5

a.first.goto "www.google.com"
#=> 2.032

a.last.goto "www.yahoo.com"
#=> 9.719

a.first.url_list
#=> ["about:blank", "http://www.google.com.ph/"]

a[1].url_list
#=> ["about:blank"]

a.last.url_list
#=> ["about:blank", "http://www.yahoo.com/"]

kind regards
-botp

···

From: Anukul Singhal [mailto:anukul.singhal@gmail.com]