Class: Watir::InputElementLocator
- Defined in:
- lib/watir/locator.rb
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.
-
#klass ⇒ Object
Returns the value of attribute klass.
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
#match_with_specifiers?, #normalize_specifiers!
Methods included from Watir
_register, _unregister, autoit, #dialog, until_with_timeout
Constructor Details
#initialize(container, types) ⇒ InputElementLocator
Returns a new instance of InputElementLocator.
128 129 130 131 132 133 |
# File 'lib/watir/locator.rb', line 128 def initialize container, types @container = container @types = types @elements = nil @klass = Element end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
126 127 128 |
# File 'lib/watir/locator.rb', line 126 def document @document end |
#element ⇒ Object
Returns the value of attribute element.
126 127 128 |
# File 'lib/watir/locator.rb', line 126 def element @element end |
#elements ⇒ Object
Returns the value of attribute elements.
126 127 128 |
# File 'lib/watir/locator.rb', line 126 def elements @elements end |
#klass ⇒ Object
Returns the value of attribute klass.
126 127 128 |
# File 'lib/watir/locator.rb', line 126 def klass @klass end |
Instance Method Details
#fast_locate ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/watir/locator.rb', line 182 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
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/watir/locator.rb', line 152 def locate count = 0 @elements.each do |object| if @klass == Element element = Element.new(object) else element = @klass.new(@container, @specifiers, nil) element.ole_object = object def element.locate; @o; end end next unless @types.include?(element.type) && match_with_specifiers?(element) count += 1 return object if count == @specifiers[:index] end nil end |
#match?(element, how, what) ⇒ Boolean
return true if the element matches the provided how and what
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/watir/locator.rb', line 171 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
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/watir/locator.rb', line 135 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 |