This is not an unusually complex problem. Testing real web applications,
you are likely to run into many similar (and more difficult) issues.

Is your wait "hack" a simple wait (i.e. a specified number of seconds)
or does it have some logic to it?

Below is a simple example of a wait that will wait as long as it takes
for the link to appear (polling every half second). If you're looking
for something more "elegant" than this, I'm not sure what you want. You
could take the logic below and make a method out of it (say
"click_wait_for_text"). That is what I would do if I needed to do this a
lot.

require 'Watir'
include Watir

$ie=IE.new
$ie.methods
$ie.goto("http://www.quinert.com/test.html";)
$ie.link(:text,"First").click

while not ($ie.link(:text,"Second").exists?)
  sleep 0.5
end

$ie.link(:text,"Second").click 

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jared Quinert
Sent: Wednesday, June 07, 2006 6:14 AM
To: [email protected]; [EMAIL PROTECTED]
Subject: [Wtr-general] Automation annoyingness

I have an issue which I suspect can only be solved elegantly by getting
our dev team to make some changes to our application.  I suspect that
the issue I'm having would be a general one with *any* tool attempting
to automate a browser (hence my crossposting).

The issue is that there is javascript attached to the 'next page' link.

This script takes some time to run before advancing to the next page.  
Watir sensibly waits for IE to not be busy after a control is clicked,
however, because the script is running, it looks like IE is not busy.  
As a result, the script clicks on the link, then immediately checks for
the elements on the next page.  They're not there, but Watir is tricked
into progressing because IE is not loading a page.

You can see the issue by running the script below.  I naively assumed
that my script would click the link to proceed then wait until the next
page had loaded.

My question is, is this a problem that is encountered frequently?  I can
imagine a few solutions -

- Have the javascript set some visible state indicator on the webpage so
that my script can wait for the state indicator to change.
- Similarly, just poll until the next page appears to be loaded, or
- Have the javascript somehow put IE into a busy/loading state
immediately.  Does anyone know if this is possible?
- Add a wait into my script, or into the click method of links (which is
my current hack).

Would love to hear suggestions.  It seems an interesting problem, and I
am sure someone else must have encountered something similar (in Watir
or some other automation effort). 

I also don't think this is something that we might reasonably expect
Watir to handle automatically, but am happy to be corrected.

Jared


require 'Watir'
include Watir

$ie=IE.new
$ie.methods
$ie.goto("http://www.quinert.com/test.html";)
$ie.link(:text,"First").click
$ie.link(:text,"Second").click
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to