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.



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

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.



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

def driver_scope
  @driver_scope
end

#element_matcherObject (readonly)

Returns the value of attribute element_matcher.



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

def element_matcher
  @element_matcher
end

Instance Method Details

#locate(built) ⇒ Object



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

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)


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

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