Class: Watir::Link

Inherits:
Element show all
Defined in:
lib/watir-classic/link.rb

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

Element::TO_S_SIZE

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Instance Method Summary collapse

Methods inherited from Element

#<=>, #__ole_inner_elements, #activeObjectHighLightColor, #assert_enabled, #assert_exists, #attribute_value, #click, #click!, #create_event, #disabled?, #dispatch_event, #document, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #initialize, #inspect, #locate, #method_missing, #ole_object, #ole_object=, #parent, #right_click, #send_keys, #style, #tag_name, #text, #to_subtype, #type_keys, #typingspeed, #visible?

Methods included from DragAndDropHelper

#drag_and_drop_by, #drag_and_drop_on

Methods included from Container

#__ole_inner_elements, #alert, #locator_for, #modal_dialog, #set_container, support_element, #wait

Methods included from Exception

message_for_unable_to_locate

Methods included from ElementExtensions

#present?, #wait_until_present, #wait_while_present, #when_present

Constructor Details

This class inherits a constructor from Watir::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Watir::Element

Instance Method Details

if an image is used as part of the link, this will return true



12
13
14
15
16
# File 'lib/watir-classic/link.rb', line 12

def link_has_image
  assert_exists
  return true if @o.getElementsByTagName("IMG").length > 0
  return false
end


28
29
30
31
32
33
34
# File 'lib/watir-classic/link.rb', line 28

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

#srcObject

this method returns the src of an image, if an image is used as part of the link



19
20
21
22
23
24
25
26
# File 'lib/watir-classic/link.rb', line 19

def src # BUG?
  assert_exists
  if @o.getElementsByTagName("IMG").length > 0
    return @o.getElementsByTagName("IMG")[0.to_s].src
  else
    return ""
  end
end

#to_sObject

returns a textual description of the link



37
38
39
40
41
42
# File 'lib/watir-classic/link.rb', line 37

def to_s
  assert_exists
  r = string_creator
  r = r + link_string_creator
  return r.join("\n")
end