On Wed, Jan 19, 2011 at 8:31 PM, vishnu <path...@gmail.com> wrote:
>
> I posted an issue on github and jarib suggested I use something like
> wait_until_present to make sure I'm on the page I expect to be. But I
> have 2 concerns.
> firstly, even with wait_until_present is there a likelyhood I get a
> stale reference error?

This error only occurs if you're trying to interact with an element
that is no longer on the page, e.g.

  button = browser.button
  # page refreshes, or the button is removed
  button.click

I think seeing this error from calling wait_until_present is very
unlikely. If you do, please create a test case I can look at.

> secondly, sometimes one of these redirects on the way might actually
> fail and throw me onto an error page. In which case I'll have to
> wait_until_present with a timeout.

As mentioned in the issue, check out the docs for these methods.
#wait_until_present and friends include a built-in timeout. You can
pass the number of seconds to wait as the first argument.

> I'd prefer a more deterministic
> approach. Is there a way for me to get watir to check if the current
> page has completely loaded AND all onload scripts have run before
> giving me control? Something I can run in a loop so that the script
> continues only when all redirects are done
>

No. Since browsers are inherently asynchronous, there's no way for the
tool to know what you consider "finished". We try to wait for the most
obvious things, but at some point we have to give control back to the
user. Consider e.g.

  <body onload="setTimeout(someFunction, 1000)">

someFunction could call out to code that does more setTimeout (or
other async calls) and eventually end up changing elements or
redirecting to some other page. The most deterministic solution you'll
get is polling the DOM for the state you want it to be in before
proceeding, which is what wait.rb in watir-webdriver was designed to
let you do easily.

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

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to