Okay. I did something like this. Downside of this implementation is that
it iterates through all elements before finding the correct one. So if
you'd search for text_field, then first it would search for a button,
then for a link and just after that text_field. You can of course change
the sequence to be something else and to include some other elements.
Also, please bear in mind, that first element, which exist with these
attributes will be returned.
I'd suggest to use b.text_field

blah, blah) instead of .element in the
future anyway, but I'll provide here one working example:
require 'watir'
class Watir::IE # monkey-patch Watir's IE class
def element *args
arg1, arg2 = args # this is needed so hashes would work as input
paremeters as with regular Watir
elements = [:button, :link, :text_field] # Watir elements which will
be searched
elements.each do |el| # iterate over each element
element = self.send(el, arg1, arg2)
return element if element.exists? # return element if it exists on
page
end
nil # return nil if element was not found
end
end
b = Watir::IE.new
b.goto "
http://www.google.com"
google_text_field = b.element

name, "q") # access text_field with two
parameters
google_button = b.element

name, "btnG") # access it with two parameters
p google_text_field.class # outputs Watir::TextField
p google_button.class # outputs Watir::Button
google_text_field.value = "ruby" # type "ruby" into search string text
field
google_button.click # and click search
puts b.text.include?("Ruby Programming Language") # outputs true
# this only works with Watir 1.6.x+ versions
puts b.element

text => "Ruby Programming Language", :index => 1).href #
multiple attributes, e.g. first link with specified text
Best regards,
Jarmo