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

#match_with_specifiers?, #normalize_specifiers!

Methods included from Watir

_register, _unregister, autoit, #dialog, until_with_timeout

Constructor Details

#initialize(container, tag) ⇒ TaggedElementLocator

Returns a new instance of TaggedElementLocator.



35
36
37
38
# File 'lib/watir/locator.rb', line 35

def initialize(container, tag)
  @container = container
  @tag = tag
end

Instance Method Details

#each_element(tag) ⇒ Object



51
52
53
54
55
# File 'lib/watir/locator.rb', line 51

def each_element tag
  @container.document.getElementsByTagName(tag).each do |ole_element|
    yield Element.new(ole_element)
  end
end

#locateObject



57
58
59
60
61
62
63
64
65
# File 'lib/watir/locator.rb', line 57

def locate
  count = 0
  each_element(@tag) do |element|
    next unless match_with_specifiers?(element)
    count += 1
    return element.ole_object if count == @specifiers[:index]
  end # elements
  nil
end

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

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/watir/locator.rb', line 67

def match?(element, how, what)
  begin
    method = element.method(how)
  rescue NameError
    raise MissingWayOfFindingObjectException,
      "#{how} is an unknown way of finding a <#{@tag}> 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}> element (#{what})"
  end
end

#set_specifier(how, what) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/watir/locator.rb', line 40

def set_specifier(how, what)
  if how.class == Hash and what.nil?
    specifiers = how
  else
    specifiers = {how => what}
  end

  @specifiers = {:index => 1} # default if not specified
  normalize_specifiers! specifiers
end