Module: Selenium::WebDriver::SearchContext

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

Constant Summary

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',
}

Instance Method Summary (collapse)

Instance Method Details

- (Element) find_element(*args)

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.

Parameters:

  • how (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)
  • what (String)

Returns:

Raises:



35
36
37
38
39
40
41
42
43
# File 'rb/lib/selenium/webdriver/common/search_context.rb', line 35

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

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

  bridge.find_element_by by, what.to_s, ref
end

- (Array<Element>) find_elements(*args)

Find all elements matching the given arguments

Parameters:

  • how (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)
  • what (String)

Returns:

See Also:



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

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

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

  bridge.find_elements_by by, what.to_s, ref
end