Class: Watir::Locators::Element::Locator

Inherits:
Object
  • Object
show all
Includes:
Exception
Defined in:
lib/watir/locators/element/locator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element_matcher) ⇒ Locator

Returns a new instance of Locator.


9
10
11
12
13
# File 'lib/watir/locators/element/locator.rb', line 9

def initialize(element_matcher)
  @query_scope = element_matcher.query_scope
  @selector = element_matcher.selector
  @element_matcher = element_matcher
end

Instance Attribute Details

#driver_scopeObject (readonly)

Returns the value of attribute driver_scope


7
8
9
# File 'lib/watir/locators/element/locator.rb', line 7

def driver_scope
  @driver_scope
end

#element_matcherObject (readonly)

Returns the value of attribute element_matcher


7
8
9
# File 'lib/watir/locators/element/locator.rb', line 7

def element_matcher
  @element_matcher
end

Instance Method Details

#locate(built) ⇒ Object


15
16
17
18
19
20
21
22
# File 'lib/watir/locators/element/locator.rb', line 15

def locate(built)
  @built = built.dup
  @driver_scope = locator_scope.wd
  @filter = :first
  matching_elements
rescue Selenium::WebDriver::Error::NoSuchElementError
  nil
end

#locate_all(built) ⇒ Object

Raises:

  • (ArgumentError)

24
25
26
27
28
29
30
31
32
# File 'lib/watir/locators/element/locator.rb', line 24

def locate_all(built)
  @built = built.dup
  @driver_scope = locator_scope.wd
  @filter = :all

  return [matching_elements].flatten unless @built.key?(:index)

  raise ArgumentError, "can't locate all elements by :index"
end