lib/watir-classic/locator.rb in watir-classic-3.3.0 vs lib/watir-classic/locator.rb in watir-classic-3.4.0
- old
+ new
@@ -1,14 +1,15 @@
module Watir
+ # @private
class Locator
include Watir
include Watir::Exception
include XpathLocator
def initialize container, specifiers, klass
@container = container
- @specifiers = {:index => Watir::IE.base_index}.merge(normalize_specifiers(specifiers))
+ @specifiers = {:index => 0}.merge(normalize_specifiers(specifiers))
@tags = @specifiers.delete(:tag_name)
@klass = klass
end
def each
@@ -129,10 +130,11 @@
def element.locate; @o; end
element
end
end
+ # @private
class TaggedElementLocator < Locator
def each_element(tag)
document.getElementsByTagName(tag).each do |ole_object|
yield create_element ole_object
end
@@ -141,19 +143,20 @@
def locate
el = locate_by_id
return el if el
return locate_elements_by_xpath_css_ole[0] if has_excluding_specifiers?
- count = Watir::IE.base_index - 1
+ count = 0
each do |element|
- count += 1
return element.ole_object if count == @specifiers[:index]
+ count += 1
end # elements
nil
end
end
+ # @private
class FrameLocator < TaggedElementLocator
def each_element(tag)
frames = @container.page_container.document.frames
i = 0
document.getElementsByTagName(tag).each do |ole_object|
@@ -163,14 +166,14 @@
i += 1
end
end
def locate
- count = Watir::IE.base_index - 1
+ count = 0
each do |frame|
- count += 1
return frame.ole_object, frame.document if count == @specifiers[:index]
+ count += 1
end
end
def locate_elements_by_xpath_css_ole
super.map do |frame|
@@ -184,18 +187,20 @@
frame
end
end
end
+ # @private
class FormLocator < TaggedElementLocator
def each_element(tag)
document.forms.each do |form|
yield create_element form
end
end
end
+ # @private
class InputElementLocator < Locator
def each_element
elements = locate_by_name || @container.__ole_inner_elements
elements.each do |object|
yield create_element object
@@ -206,13 +211,13 @@
def locate
el = locate_by_id
return el if el
return locate_elements_by_xpath_css_ole[0] if has_excluding_specifiers?
- count = Watir::IE.base_index - 1
+ count = 0
each do |element|
- count += 1
return element.ole_object if count == @specifiers[:index]
+ count += 1
end
end
def each
if has_excluding_specifiers?