Class: Watir::InputElementLocator
- Defined in:
- lib/watir/locator.rb
Constant Summary
Constants included from Watir
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#element ⇒ Object
Returns the value of attribute element.
-
#elements ⇒ Object
Returns the value of attribute elements.
Instance Method Summary collapse
- #fast_locate ⇒ Object
-
#initialize(container, types) ⇒ InputElementLocator
constructor
A new instance of InputElementLocator.
- #locate ⇒ Object
-
#match?(element, how, what) ⇒ Boolean
return true if the element matches the provided how and what.
- #specifier=(arg) ⇒ Object
Methods inherited from Locator
Methods included from Watir
_register, _unregister, autoit, #dialog, until_with_timeout
Constructor Details
#initialize(container, types) ⇒ InputElementLocator
Returns a new instance of InputElementLocator.
94 95 96 97 98 |
# File 'lib/watir/locator.rb', line 94 def initialize container, types @container = container @types = types @elements = nil end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
92 93 94 |
# File 'lib/watir/locator.rb', line 92 def document @document end |
#element ⇒ Object
Returns the value of attribute element.
92 93 94 |
# File 'lib/watir/locator.rb', line 92 def element @element end |
#elements ⇒ Object
Returns the value of attribute elements.
92 93 94 |
# File 'lib/watir/locator.rb', line 92 def elements @elements end |
Instance Method Details
#fast_locate ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/watir/locator.rb', line 150 def fast_locate # Searching through all elements returned by ole_inner_elements # is *significantly* slower than IE's getElementById() and # getElementsByName() calls when how is :id or :name. However # IE doesn't match Regexps, so first we make sure what is a String. # In addition, IE's getElementById() will also return an element # where the :name matches, so we will only return the results of # getElementById() if the matching element actually HAS a matching # :id. the_id = @specifiers[:id] if the_id && the_id.class == String && @specifiers[:index] == 1 && @specifiers.length == 2 @element = @document.getElementById(the_id) rescue nil # Return if our fast match really HAS a matching :id return true if @element && @element.invoke('id') == the_id end the_name = @specifiers[:name] if the_name && the_name.class == String @elements = @document.getElementsByName(the_name) rescue nil end false end |
#locate ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/watir/locator.rb', line 117 def locate count = 0 @elements.each do |object| element = Element.new(object) catch :next_element do throw :next_element unless @types.include?(element.type) @specifiers.each do |how, what| next if how == :index unless match? element, how, what throw :next_element end end count += 1 throw :next_element unless count == @specifiers[:index] return object end end nil end |
#match?(element, how, what) ⇒ Boolean
return true if the element matches the provided how and what
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/watir/locator.rb', line 139 def match? element, how, what begin attribute = element.send(how) rescue NoMethodError raise MissingWayOfFindingObjectException, "#{how} is an unknown way of finding an <INPUT> element (#{what})" end what.matches(attribute) end |
#specifier=(arg) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/watir/locator.rb', line 100 def specifier= arg how, what, value = arg if how.class == Hash and what.nil? specifiers = how else specifiers = {how => what} end @specifiers = {:index => 1} # default if not specified if value @specifiers[:value] = value.is_a?(Regexp) ? value : value.to_s end normalize_specifiers! specifiers end |