On Mon, Aug 1, 2011 at 5:41 PM, Jarmo Pertman <jarm...@gmail.com> wrote:
> In Watir the locating of the element will be done automatically - why
> not use the same approach in Watir-WebDriver? Is there any good reason
> to do that?
>
> It just sucks that i can't write code similar to this in watir-
> webdriver:
> container = browser.div
> # do something, which obsoletes the element, but makes it exist again
> container.do_something # this should work
>
> As i understand from your gist then #do_something won't work unless i
> specifically tell again that container = browser.div. Why?
>

That code will work just fine, since the div isn't located until you
use "container". However, you'll need to re-locate if the element was
used once (and thus located and the reference saved), then removed
from the page and then used again, like in my example.

That behaviour is up for debate, but personally I've always considered
the current behaviour more helpful than not: it tells me very
specifically where my expectations are wrong and where there are
potential race conditions. Automatically re-locating gives me less
information about the interaction between the test and the app than
the ObsoleteElementErrors do, which helps me write more robust tests.
The application's behaviour isn't hidden from the test author, and
that's always a good thing IMO.

Another benefit is the overhead saved by not having to go through the
"locate" algorithm every time the element is used, which I believe is
what happens in Watir. If you're reusing Element instances heavily,
Watir-WebDriver benefits from caching the element reference.

That being said I do see that this is a break with Watir 1.X and
somewhat inconsistent with Watir's element objects, where you never
really know whether the element is "live" or not (by re-locating on
every use).  The current behaviour is sort of a compromise between
Watir's Element objects that just stores *how* to find the element,
and what you'll find in WebDriver, where every Element instance
*always* is a pointer to a DOM node.

Any other opinions on this?

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