I tried to use the function that you had put up at the link below:
 http://aspn.activestate.com/ASPN/Mail/Message/ruby-talk/3690066

 Made a few changes though:
 def element *args
 arg1, arg2 = args # this is needed so hashes would work as input
 elements =
[ :table, :link, :cell, :image, :checkbox, :radio, :text_field, :select_list, 
:button]
# Watir elements which
 elements.each do |el| # iterate over each element
 element = self.send(el, arg1, arg2)
 return element if element.exists? # return element if it exists
 end
 nil # return nil if element was not found
 end
 end

 Added a few elements more.
 Now the problem I am facing with this is that when I use it with a
select-multiple list, I get an error "c:/ruby/lib/ruby/gems/1.8/gems/
watir-1.6.2/lib/watir/input_elements.rb:525:in `method_missing':
unknown property or method `checked' (WIN32OLERuntimeError)", which
means it is taking it as a checkbox. Now if I delete ':checkbox' from
the elements array of the function, it takes up the next element
instead of taking up ':select_list'.
 Does the job apparently if I put up ':select_list' before ':checkbox'
in the array, still gives me an error "c:/ruby/lib/ruby/gems/1.8/gems/
watir-1.6.2/lib/watir/input_elements.rb:68:in
`select_item_in_select_list': undefined method `matches' for
nil:NilClass (NoMethodError)"

 Please do let me know a possible solution to this.

 Thanks and Regards,
 Betsy Joy.

On Jan 19, 2:19 pm, Jarmo Pertman <jarm...@gmail.com> wrote:
> Hello.
>
> As I answered to your question in Ruby-Forum, I'm going to paste the
> answer here also. I used different approach than xpath, since I've
> discovered that XPath in Watir+IE is really-really slow. I haven't
> benchmarked my current solution, but last time I tried something like
> text_field(:name, /blah/) or text_field(:name, "blah") or text_field
> (:xpath, "blah") then with xpath it took about 100x+ more time than
> with other solutions. It has mentioned somewhere else before that
> Watir builds up DOM and then gets stuff from that with XPath or
> something. Maybe someone could say about that in little more detail.
>
> Anyway, there is my solution for that problem, give it a try and
> benchmark it against xpath solution if you'd like:
> 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 firstelement, which exist with these
> attributes will be returned.
>
> I'd suggest to use b.text_field(:blah, blah) instead of .elementin
> the
> future anyway, but I'll provide here one working example:
>
> require 'watir'
>
> class Watir::IE # monkey-patch Watir's IE class
>   defelement*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 eachelement
>      element= self.send(el, arg1, arg2)
>
>       returnelementifelement.exists? # returnelementif it exists
> on
> page
>     end
>     nil # return nil ifelementwas not found
>   end
> end
>
> b = Watir::IE.new
> b.goto "http://www.google.com";
>
> google_text_field = b.element(:name, "q") #accesstext_field with
> two
> parameters
>
> google_button = b.element(:name, "btnG") #accessit 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to watir-general@googlegroups.com
Before posting, please read the following guidelines: 
http://wiki.openqa.org/display/WTR/Support
To unsubscribe from this group, send email to 
watir-general-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/watir-general
-~----------~----~----~----~------~----~------~--~---

Reply via email to