I had the same problem with one of the application I test
and what I had to do is something like:
$ie.link(:text, 'View Report').click
↓ – the
url (or part of) initially displayed in the title bar
ie2 = IE.attach( :url, /index.html/i )
puts ie2.status()
ie2 = IE.attach( :title, /View Report/ )
puts ie2.status()
# stuff happens
ie2.close
The first status will halt the application until the ‘done’
status is reached and then it moves on to the next line.
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Paul Carvalho
Sent: Monday, March 20, 2006 1:33
PM
To: [email protected]
Subject: [Wtr-general] How can my
script wait until a new window hasfinished loading before using IE.attach?
Hello again,
I am having a bit of difficulty getting my script to wait for a window to
finish loading before attaching to it. Here's the original code:
----
$ie.link(:text, 'View Report').click
ie2 = IE.attach(:title, /View Report/)
# stuff happens
ie2.close
----
If I run it as above, I get the following error:
"Watir::Exception::NoMatchingWindowFoundException: Unable to locate a
window with title of (?-mix:View Report)"
The problem seems to be that the Title bar initially has a URL displayed in it
and then, after a while (random number of seconds), it updates to the correct
<TITLE>. So the command will *eventually* work, but it will fail if
it checks the window too soon.
I tried inserting a 'sleep' command between the first two lines above, but I
can't account for how long it will take the window to finish loading.
I searched the message archives but I couldn't find anything that helps me tell
the script to wait as long as it needs before trying to attach to the new
window.
I tried making up combinations of functions to try and help me, but so far
nothing has helped. For example, I tried working with commands like:
> IE.attach(:title, /View
Report/).exists? # but this doesn't work as I'd like
and the ie.status() method only applies when you can actually connect to the
window first, so it doesn't help me either.
I thought about creating a series of nested begin-rescue-end blocks to catch
and work with the exceptions, but I still couldn't quite figure out how to get
it to wait the random amount of time required before trying to attach to the
window.
Has anyone else encountered a similar problem before? Do you have any
suggestions that might help?
Please let me know. Thanks.
Paul.