Module: Selenium::WebDriver::SearchContext

Included in:
Driver, Element
Defined in:
lib/selenium/webdriver/common/search_context.rb

Constant Summary collapse

FINDERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  class: 'class name',
  class_name: 'class name',
  css: 'css selector',
  id: 'id',
  link: 'link text',
  link_text: 'link text',
  name: 'name',
  partial_link_text: 'partial link text',
  tag_name: 'tag name',
  xpath: 'xpath'
}.freeze

Instance Method Summary collapse

Instance Method Details

#find_element(how, what) ⇒ Element #find_element(opts) ⇒ Element

Find the first element matching the given arguments

When using Element#find_element with :xpath, be aware that webdriver follows standard conventions: a search prefixed with “//” will search the entire document, not just the children of this current node. Use “.//” to limit your search to the children of the receiving Element.

Overloads:

  • #find_element(how, what) ⇒ Element

    Parameters:

    • how (Symbol, String)

      The method to find the element by

    • what (String)

      The locator to use

  • #find_element(opts) ⇒ Element

    Parameters:

    • opts (Hash)

      Find options

    Options Hash (opts):

    • :how (Symbol)

      Key named after the method to find the element by, containing the locator

Returns:

Raises:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/selenium/webdriver/common/search_context.rb', line 56

def find_element(*args)
  how, what = extract_args(args)

  by = FINDERS[how.to_sym]
  raise ArgumentError, "cannot find element by #{how.inspect}" unless by

  bridge.find_element_by by, what.to_s, ref
rescue Selenium::WebDriver::Error::TimeOutError
  # Implicit Wait times out in Edge
  raise Selenium::WebDriver::Error::NoSuchElementError
end

#find_elements(*args) ⇒ Object

Find all elements matching the given arguments

See Also:



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/selenium/webdriver/common/search_context.rb', line 74

def find_elements(*args)
  how, what = extract_args(args)

  by = FINDERS[how.to_sym]
  raise ArgumentError, "cannot find elements by #{how.inspect}" unless by

  bridge.find_elements_by by, what.to_s, ref
rescue Selenium::WebDriver::Error::TimeOutError
  # Implicit Wait times out in Edge
  []
end