Sha256: eefc31f7b71e9c9f9a34a03129bcad1bf5f9a54d86dacb93c8e1f600044e730e

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

module FireWatir
  #
  # Description:
  #   Class for Link element.
  #
  class Link < Element
    attr_accessor :element_name
    TAG = 'A'
    #
    # Description:
    #   Initializes the instance of link element.
    #
    # Input:
    #   - how - Attribute to identify the link element.
    #   - what - Value of that attribute.
    #
    def initialize(container, how, what)
      @how = how
      @what = what
      @container = container
    end

    #
    # Description:
    #   Locate the link element on the page.
    #
    def locate
      case @how
      when :jssh_name
        @element_name = @what
      when :xpath
        @element_name = element_by_xpath(@container, @what)
      else
        @element_name = locate_tagged_element('A', @how, @what)
      end
      @o = self
    end

    #TODO: if an image is used as part of the link, this will return true
    #def link_has_image
    #    assert_exists
    #    return true  if @o.getElementsByTagName("IMG").length > 0
    #    return false
    #end

    #TODO: this method returns the src of an image, if an image is used as part of the link
    #def src # BUG?
    #    assert_exists
    #    if @o.getElementsByTagName("IMG").length > 0
    #        return  @o.getElementsByTagName("IMG")[0.to_s].src
    #    else
    #        return ""
    #    end
    #end

    #
    # Description:
    #   Used to populate the properties in to_s method.
    #
    #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

    # returns a textual description of the link

    def to_s
      assert_exists
      super({"href" => "href","inner text" => "text"})
    end

  end # Link
end # FireWatir

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mk_firewatir-1.6.5 lib/firewatir/elements/link.rb
firewatir-1.6.5 lib/firewatir/elements/link.rb