haha I was actually considering this, but here I can see the race
condition where the readystate might be complete before the onload
fires.

Another idea I had was to in a wait block
attachEventListener to document load a function of the form
setTimeout(0, function(){}) and my attached function would set some
element on the page and use watir to check for this element. This way
the element I attach will eventually exist on the correct page or on
any of various error pages.
What do you think of this approach? Are there some pitfalls I'm
missing? If it seems that this too is likely to fail, then I'll just
poll for the elements I expect on the success page as you suggest.

On Thu, Jan 20, 2011 at 4:58 PM, Jari Bakken <jari.bak...@gmail.com> wrote:
> On Thu, Jan 20, 2011 at 12:06 PM, vishnu <path...@gmail.com> wrote:
>> Ideally in the case of these redirects, I'd like to be able to check
>> if watir believes the page is loaded AND if no javascript is currently
>> executing, because I know that in this specific case, on none of my
>> pages do I have to worry about javascript running on a setTimeout.
>> Done is well defined in my case. Is it possible for me to check that
>> my definition of done is true?
>
> JavaScript is always "currently executing" - i.e. the event loop is
> always running. At no point will the browser throw up its hands and
> say "all done!" - the closest you'll get is polling the document's
> readyState property
>
>  browser.execute_script("return document.readyState") == "complete"
>
> but in my experience, relying on this sort of stuff as a generic
> mechanism leads to race conditions and a lot of flaky tests. My
> advice: poll for the elements you want to interact with to be there.
>
> --
> 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
>

-- 
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