the 'why' in this case is just 'that's how it works'.  I'm by no means
a ruby expert, but let me see if I can explain this (ruby experts are
invited to correct me if any of this is wrong)

All variables in ruby are holding references to objects.   If you do
myvar=12  myvar is holding a reference to the constant '12'.  If you
do myvar= browser.textfield(h,w)  then myvar is holding a reference to
a specific text_field object within the browser object.  However that
reference is basically to that specifric object, not just any object
of type text_field with the identifiers you specified, but that
specific unique one.  More importantly it's not making a copy of the
item or anything of that sort.  When you change pages, the contents of
browser object  are completely changed, there might be another
text_field object there with the same id but it's a different object.
your reference is pointing to the original one, which is no longer
present inside the browser object.

when you use myvar=browser.text_field(h,w).value, it's returning a
reference to a text string (effectively a copy created by that
method), which in that case is not tied to the browser object, and
it's going to remain in memory until you change myvar.  At that point
the browser object can change all it wants, you still have your
reference to a copy of the value that was inside that text_field
object

On May 27, 9:53 am, Abe Heward <[email protected]> wrote:
> Yes. I understand the mechanics of what's going on.  I was wondering the
> why, though.
>
> Sadly, it looks like it's the same amount of code to write, either way you
> go.

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

Reply via email to