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!, #click_no_wait, #document, #enabled?, #exists?, #fire_event, #flash, #focus, #inspect, #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, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #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 |
Instance Method Details
#link_has_image ⇒ Object
if an image is used as part of the link, this will return true
32 33 34 35 36 |
# File 'lib/watir/link.rb', line 32 def link_has_image assert_exists return true if @o.getElementsByTagName("IMG").length > 0 return false end |
#link_string_creator ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/watir/link.rb', line 48 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 |
# File 'lib/watir/link.rb', line 19 def locate if @how == :xpath @o = @container.element_by_xpath(@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
39 40 41 42 43 44 45 46 |
# File 'lib/watir/link.rb', line 39 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
57 58 59 60 61 62 |
# File 'lib/watir/link.rb', line 57 def to_s assert_exists r = string_creator r = r + link_string_creator return r.join("\n") end |