On 3/23/06, Mike Kolcun <[EMAIL PROTECTED]> wrote:
>
> I've got a situation where I have a the main window of an application that
> pops up a new window using a JavaScript call on the click of a form button.
>
> The title of this new window varies from time to time with what I'm testing,
> so I'm not able to just attach to the title of the window. The url is also
> different, so that option is out too.
>
> Is there a way to get a handle for "the most recently opened window" or
> something of the like?
If it's safe to assume that the only two browser windows open will be
the parent window and the popup window, then the following example
might work for you. There may be a more graceful way to do this, but
this seemed to work when I tested it out. Also, if more than two
windows are open, then it will probably not do the right thing,
either. :) In that case it may match the wrong window.
The technique of using the regexp "//" to loop through all browsers is
from an example for closing all open browsers that someone posted to
the list a while ago.
== BEGIN CODE SNIPPET ==
unwantedTitle = ie.title # assumes 'ie' contains your parent browser.
done = 'unknown'
while (done != 'yes')
# Start looping through all open browsers.
begin
header = Regexp.new(//)
tempIE = IE.attach(:title, header)
# The first time the temp IE title does not match the parent's title,
# assume we're done and bail out of the loop, saving the match in 'ie2'
if (tempIE.title != unwantedTitle)
ie2 = tempIE
done = 'yes'
end
rescue NoMatchingWindowFoundException
# If we didn't find a match, just leave the loop.
done = 'yes'
end
end
p ie2.title # to check what browser was matched
== END CODE SNIPPET ==
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general