# Watir: Need help in defining a dynamic array

**URL:** <https://www.ruby-forum.com/t/watir-need-help-in-defining-a-dynamic-array/138106>\
**Category:** Ruby\
**Created:** [May 20, 2008, 9:37am UTC](https://www.ruby-forum.com/t/watir-need-help-in-defining-a-dynamic-array/138106 "2008-05-20T09:37:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anukulsinghal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@anukulsinghal](https://www.ruby-forum.com/u/anukulsinghal)\
**Post date:** [May 20, 2008, 9:37am UTC](https://www.ruby-forum.com/t/watir-need-help-in-defining-a-dynamic-array/138106/1 "2008-05-20T09:37:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anukulsinghal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@anukulsinghal](https://www.ruby-forum.com/u/anukulsinghal)\
**Post date:** [May 20, 2008, 10:09am UTC](https://www.ruby-forum.com/t/watir-need-help-in-defining-a-dynamic-array/138106/2 "2008-05-20T10:09:57Z")

</div>

From: Anukul S. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# 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](http://www.google.com)”  
#=\> 2.032

a.last.goto “[www.yahoo.com](http://www.yahoo.com)”  
#=\> 9.719

a.first.url\_list  
#=\> [“about:blank”, “[http://www.google.com.ph/](http://www.google.com.ph/)”]

a[1].url\_list  
#=\> [“about:blank”]

a.last.url\_list  
#=\> [“about:blank”, “[http://www.yahoo.com/](http://www.yahoo.com/)”]

kind regards  
-botp
