With the exception of using ID as the identifier, You can't do a
generic element, you need to invoke a method that is specific to the
element type, but if you know what kind of tag, then you know what
type of element (since tags define the elements)

You can access most elements by multiple means   Excepting the case of
attaching to a new browser window, ID, Name, Index, are nearly
universal, class works for everything but frames,  and 'text' works
for a majority of elements, and looks for the element according to the
text within it.

Using the contained text is often a great way to select a specific
div, link, cell, or even a row (sometimes via a reg-ex match on some
unique bit of text that will be found on that row).

'Clickable' text is almost always contained in some kind of other
element, it's really rare to see it 'naked' at the body level, just
purely due to the needs of isolating the 'clickability' to that text
only, instead of the entire body.  So generally if you know the
element, you can use .click on it.  If that doesn't work, have a
closer look at the HTML and try to find what javascript event is being
watched for, and fire that event at the element

Now, (unless it was changed recently) there is a bit of a loophole
with respect to identifying things by ID.  (and I'd recommend some
experimentation to validate this works for you, it's not a tactic I
use).  Since ID's are supposed to be unique within the document, it
appears that if you identify an element by ID, watir doesn't 'care'
about matching the element type, it just looks for the first
occurrence of that one specific ID, and returns whatever it finds. It
doesn't look to see if there's more than one (there never should be as
it's supposed to be unique) nor does it work well to use ID combined
with some other attribute (which in theory, you should never need to
do).  I've run into this by accident, where I specified the id wrong,
and despite asking for element type x, it returned element y which a
matching ID.

I don't know if that's intentional, or just a byproduct of the
assumption that the html will be valid, ID's will be unique, etc.
I've always considered it an 'undocumented feature' and hesitated to
use it in any of my scripts.

Sample html would help, or at the very least, what kind of tag

On Aug 18, 4:23 am, TCBlues <tcbl...@gmail.com> wrote:
> So it is not possible to access using something like
> brow.element(:id,"xxx") or brow.object(:id,"xxx") or something
> similar.
> The only way is to know before hand what kind of tag we'll be
> accessing.

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

You received this message because you are subscribed to 
http://groups.google.com/group/watir-general
To post: watir-general@googlegroups.com
To unsubscribe: watir-general+unsubscr...@googlegroups.com

Reply via email to