Capture the state of an element in time?

10 views
Skip to first unread message

Jamison Dance

unread,
Feb 22, 2012, 4:45:24 PM2/22/12
to watir-...@googlegroups.com
Is there any way to capture the current state of an element? I have some elements that start off in a default state, and once the page finishes loading JavaScript changes their state. I select the elements in Watir, but by the time my tests run the JavaScript has already run on the page. I would like to know the state (mostly the class, but some other things as well) of an element when it first appears, not at the moment the page runs. Is there a way to do this in Watir?

Željko Filipin

unread,
Feb 22, 2012, 4:52:03 PM2/22/12
to watir-...@googlegroups.com
On Wed, Feb 22, 2012 at 3:45 PM, Jamison Dance <jerg...@gmail.com> wrote:
> Is there any way to capture the current state of an element?

Sure, try this:

browser.element.html

I think both watir and watir-webdriver gems support attribute_value, too:

Chuck van der Linden

unread,
Feb 22, 2012, 5:39:45 PM2/22/12
to Watir General


On Feb 22, 1:52 pm, Željko Filipin <zeljko.fili...@gmail.com> wrote:
> On Wed, Feb 22, 2012 at 3:45 PM, Jamison Dance <jerga...@gmail.com> wrote:
> > Is there any way to capture the current state of an element?
>
> Sure, try this:
>
> browser.element.html
>
> I think both watir and watir-webdriver gems support attribute_value, too:
>
> http://rubydoc.info/gems/watir-webdriver/Watir/Element#attribute_valu...http://rubydoc.info/gems/watir/Watir/Element#attribute_value-instance...
>
> Željko
> --
> watir.com/book - author

The problem is, if there is javascript that is running 'onload' then
it's going to be a race between watir trying to examine the object,
and javascript that might be modifying it.

potentially to automate somethign like this, you might have to request
the HTML directly with something like HTTP-Party, parse it with
something like nokogiri, and pull out the stated attributes that would
be there as the page loads, and before any CSS rules or Javascript
have done their thing.

if you just want to observe and verify and not automate a test for
this, something like fiddler2 (if you are on windows) would let you
look at every raw file that went into composing the page, as they were
transferred from the server, so you could find the thing in the HTML
files, and compare the attributes there with what is seen in the dom
using developer tools. Developer tools can also show you things like
applied styles etc.

What is the purpose of a test like this? seems like a fair bit of
effort, and if the item is being altered on the fly, does the original
state really matter that much, or just that it ends up in the correct
state after all CSS rules and Javascript have done their thing?
Reply all
Reply to author
Forward
0 new messages