[wtr-general] Re: Access an object

2009-02-17 Thread Isabel


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



[wtr-general] Re: Access an object

2009-01-19 Thread Jarmo Pertman

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



[wtr-general] Re: Access an object

2009-01-14 Thread TCBlues

Thanks a lot.

On 14 ene, 03:59, Richard Lawrence rslawre...@gmail.com wrote:
 You don't get back the specific object type from element_by_xpath, so
 some methods don't work. But this works:

 b = Watir::IE.new
 b.goto 'http://www.google.com/'
 txt = b.element_by_xpath(//*...@name='q'])
 txt.value = 'Richard Lawrence'
 btn = b.element_by_xpath(//*...@name='btnG'])
 btn.click

 So you might try the value property instead of the set method.

 Richard

 On Tue, Jan 13, 2009 at 9:46 AM, TCBlues tcbl...@gmail.com wrote:

  Thanks for your answer.

  In the case the object is a textField or a listField I'm trying to set
  the control with:
  ie.element_by_xpath(//*...@name=imp1]).set(testing)

  but an error comes up: 13:in `method_missing': unknown property or
  method `set' (WIN32OLERuntimeError)
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[wtr-general] Re: Access an object

2009-01-14 Thread wesley chen
Thanks very much. I study from you again, :)
Thanks.
Wesley Chen.


On Wed, Jan 14, 2009 at 11:59 AM, Richard Lawrence rslawre...@gmail.comwrote:


 You don't get back the specific object type from element_by_xpath, so
 some methods don't work. But this works:

 b = Watir::IE.new
 b.goto 'http://www.google.com/'
 txt = b.element_by_xpath(//*...@name='q'])
 txt.value = 'Richard Lawrence'
 btn = b.element_by_xpath(//*...@name='btnG'])
 btn.click

 So you might try the value property instead of the set method.

 Richard

 On Tue, Jan 13, 2009 at 9:46 AM, TCBlues tcbl...@gmail.com wrote:
 
  Thanks for your answer.
 
  In the case the object is a textField or a listField I'm trying to set
  the control with:
  ie.element_by_xpath(//*...@name=imp1]).set(testing)
 
  but an error comes up: 13:in `method_missing': unknown property or
  method `set' (WIN32OLERuntimeError)
 

 


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



[wtr-general] Re: Access an object

2009-01-13 Thread Richard Lawrence

This ought to do it:

  require 'watir'
  include Watir
  ie=IE.new
  ie.goto(file://c:/temp2.htm)
  ie.element_by_xpath(//*...@name='imp1']).click()

Richard
--
Richard Lawrence
Certified Scrum Coach
Founder and Principal Consultant, Humanizing Work, LLC
303-895-7688
rich...@humanizingwork.com
www.humanizingwork.com
www.richardlawrence.info

On Tue, Jan 13, 2009 at 3:30 AM, TCBlues tcbl...@gmail.com wrote:

 I need to access an object through the name without knowing wich kind
 of object is.

 For example the control could be a button or a link and I would like
 to do something like:

 require 'watir'
 include Watir
 ie=IE.new
 ie.goto(file://c:/temp2.htm)

 ie.object(:name,imp1).click()

 Is there any way

 Thank you in advance.


 


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



[wtr-general] Re: Access an object

2009-01-13 Thread Tiffany Fodor

Hi!

The only way I know to do this would be to perform an exists? check on
the various objects that this could be and click it if it exists.

if ie.button(:name, 'imp1').exists?
   ie.button(:name, 'imp1').click
elsif ie.link(:name, 'imp1').exists?
   ie.link(:name, 'imp1').click
end

Hope this helps!

-Tiffany

On Jan 13, 3:30 am, TCBlues tcbl...@gmail.com wrote:
 I need to access an object through the name without knowing wich kind
 of object is.

 For example the control could be a button or a link and I would like
 to do something like:

 require 'watir'
 include Watir
 ie=IE.new
 ie.goto(file://c:/temp2.htm)

 ie.object(:name,imp1).click()

 Is there any way

 Thank you in advance.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[wtr-general] Re: Access an object

2009-01-13 Thread TCBlues

Thanks for your answer.

In the case the object is a textField or a listField I'm trying to set
the control with:
ie.element_by_xpath(//*...@name=imp1]).set(testing)

but an error comes up: 13:in `method_missing': unknown property or
method `set' (WIN32OLERuntimeError)


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



[wtr-general] Re: Access an object

2009-01-13 Thread wesley chen
We can't use set, exists? and many other methods after comment
:element_by_xpath

Thanks.
Wesley Chen.


On Wed, Jan 14, 2009 at 12:46 AM, TCBlues tcbl...@gmail.com wrote:


 Thanks for your answer.

 In the case the object is a textField or a listField I'm trying to set
 the control with:
 ie.element_by_xpath(//*...@name=imp1]).set(testing)

 but an error comes up: 13:in `method_missing': unknown property or
 method `set' (WIN32OLERuntimeError)


 


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



[wtr-general] Re: Access an object

2009-01-13 Thread Richard Lawrence

You don't get back the specific object type from element_by_xpath, so
some methods don't work. But this works:

b = Watir::IE.new
b.goto 'http://www.google.com/'
txt = b.element_by_xpath(//*...@name='q'])
txt.value = 'Richard Lawrence'
btn = b.element_by_xpath(//*...@name='btnG'])
btn.click

So you might try the value property instead of the set method.

Richard

On Tue, Jan 13, 2009 at 9:46 AM, TCBlues tcbl...@gmail.com wrote:

 Thanks for your answer.

 In the case the object is a textField or a listField I'm trying to set
 the control with:
 ie.element_by_xpath(//*...@name=imp1]).set(testing)

 but an error comes up: 13:in `method_missing': unknown property or
 method `set' (WIN32OLERuntimeError)


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