Class: Watir::TaggedElementLocator

Inherits:
Locator
  • Object
show all
Defined in:
lib/watir/locator.rb

Direct Known Subclasses

ElementLocator, FormLocator, FrameLocator

Instance Method Summary collapse

Methods inherited from Locator

#create_element, #document, #has_excluding_specifiers?, #locate_by_id, #locate_by_xpath_css_ole, #match_with_specifiers?, #normalize_specifiers!, #set_specifier

Methods included from Watir

until_with_timeout

Constructor Details

#initialize(container, tag, klass) ⇒ TaggedElementLocator

Returns a new instance of TaggedElementLocator.



88
89
90
91
92
# File 'lib/watir/locator.rb', line 88

def initialize(container, tag, klass)
  @container = container
  @tag = tag
  @klass = klass || Element
end

Instance Method Details

#eachObject



100
101
102
103
104
105
106
# File 'lib/watir/locator.rb', line 100

def each
  each_element(@tag) do |element| 
    next unless match_with_specifiers?(element)
    yield element          
  end 
  nil
end

#each_element(tag) ⇒ Object



94
95
96
97
98
# File 'lib/watir/locator.rb', line 94

def each_element tag
  document.getElementsByTagName(tag).each do |ole_object|
    yield create_element ole_object
  end
end

#locateObject



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/watir/locator.rb', line 108

def locate
  el = locate_by_id
  return el if el
  return locate_by_xpath_css_ole if has_excluding_specifiers?

  count = Watir::IE.base_index - 1
  each do |element|
    count += 1
    return element.ole_object if count == @specifiers[:index]
  end # elements
  nil
end

#match?(element, how, what) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/watir/locator.rb', line 121

def match?(element, how, what)
  begin
    method = element.method(how)
  rescue NameError
    raise MissingWayOfFindingObjectException,
      "#{how} is an unknown way of finding a <#{@tag || @tags.join(", ")}> element (#{what})"
  end
  case method.arity
  when 0
    what.matches method.call
  when 1
    method.call(what)
  else
    raise MissingWayOfFindingObjectException,
      "#{how} is an unknown way of finding a <#{@tag || @tags.join(", ")}> element (#{what})"
  end
end