Class: Watir::Link
Overview
This class is the means of accessing a link on a page Normally a user would not need to create this object as it is returned by the Watir::Container#link method many of the methods available to this object are inherited from the Element class
Constant Summary
Constants inherited from Element
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed
Instance Method Summary collapse
-
#initialize(container, how, what) ⇒ Link
constructor
Returns an initialized instance of a link object * container - an instance of a container * how - symbol - how we access the link * what - what we use to access the link, text, url, index etc.
-
#link_has_image ⇒ Object
if an image is used as part of the link, this will return true.
- #link_string_creator ⇒ Object
- #locate ⇒ Object
-
#src ⇒ Object
this method returns the src of an image, if an image is used as part of the link.
-
#to_s ⇒ Object
returns a textual description of the link.
Methods inherited from Element
#<=>, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #document, #enabled?, #exists?, #fire_event, #flash, #focus, #inspect, #method_missing, #ole_object, #ole_object=, #parent, #text, #type_keys, #typingspeed, #visible?
Methods included from Container
#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #element_by_css, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #hidden, #hiddens, #image, #images, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #log, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields, #wait
Constructor Details
#initialize(container, how, what) ⇒ Link
Returns an initialized instance of a link object
* container - an instance of a container
* how - symbol - how we access the link
* what - what we use to access the link, text, url, index etc
12 13 14 15 16 17 |
# File 'lib/watir/link.rb', line 12 def initialize(container, how, what) set_container container @how = how @what = what super(nil) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Watir::Element
Instance Method Details
#link_has_image ⇒ Object
if an image is used as part of the link, this will return true
34 35 36 37 38 |
# File 'lib/watir/link.rb', line 34 def link_has_image assert_exists return true if @o.getElementsByTagName("IMG").length > 0 return false end |
#link_string_creator ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/watir/link.rb', line 50 def link_string_creator n = [] n << "href:".ljust(TO_S_SIZE) + self.href n << "inner text:".ljust(TO_S_SIZE) + self.text n << "img src:".ljust(TO_S_SIZE) + self.src if self.link_has_image return n end |
#locate ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/watir/link.rb', line 19 def locate if @how == :xpath @o = @container.element_by_xpath(@what) elsif @how == :css @o = @container.element_by_css(@what) else begin @o = @container.locate_tagged_element('A', @how, @what) rescue UnknownObjectException @o = nil end end end |
#src ⇒ Object
this method returns the src of an image, if an image is used as part of the link
41 42 43 44 45 46 47 48 |
# File 'lib/watir/link.rb', line 41 def src # BUG? assert_exists if @o.getElementsByTagName("IMG").length > 0 return @o.getElementsByTagName("IMG")[0.to_s].src else return "" end end |
#to_s ⇒ Object
returns a textual description of the link
59 60 61 62 63 64 |
# File 'lib/watir/link.rb', line 59 def to_s assert_exists r = string_creator r = r + link_string_creator return r.join("\n") end |