Watir question regarding to Browser


I want to gain the control of last opened browser.How would I do that?
For an example


this is returning the window object but I want IE object thereby I could
able to access function inside WATIR::Browser, So how would I do this?

Try b = browser.windows.last.browser


It’s working perfect, thank you.

hi Joel P.,

I was using WATIR::IE.attach(:index,1) to attach the browser. Now I am
using $browser1 = $browser.windows.last.browser and the problem
with this type of attachment is, before the browser is completely
loaded, next operation is performed, For an example,

line 1:$browser1 = $browser.windows.last.browser
line 2:$browser.link(:id,‘something’).click

Line number 2 is executed before the page loads completely. So it gives
the error of unable to locate the element, Now If use sleep statement in
between line1 and line 2 like below

line 1:$browser1 = $browser.windows.last.browser
sleep 2
line 2:$browser.link(:id,‘something’).click

it works, But it’s not an ideal solution because browser loading time
varies. The same problem did not occur while I was using
WATIR::IE.attach(:index,1). So could you please tell me how to overcome
this problem?

Wait for the page to load before line 1

yes that’s what I am putting sleep statement in between, but are you
saying someother way?

Depending on your version of Watir, this might work:


hi thank you.

when_present is working here, But I wrongly typed the code, Actually it

line 1:$browser1 = $browser.windows.last.browser

line 2: parseHTML($browser1.table(:class,‘something’).html)

hi Thank you.
I use your code but still it’s not reading. It’s ok, I swifted to attach
browser using index now.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs