Module: Selenium::WebDriver::Find

Included in:
Driver, Element, Remote::Bridge
Defined in:
lib/selenium/webdriver/find.rb

Constant Summary collapse

FINDERS =
{
  :class             => 'ClassName',
  :class_name        => 'ClassName',
  :css               => 'CssSelector',
  :id                => 'Id',
  :link              => 'LinkText',
  :link_text         => 'LinkText',
  :name              => 'Name',
  :partial_link_text => 'PartialLinkText',
  :tag_name          => 'TagName',
  :xpath             => 'Xpath',
}

Instance Method Summary collapse

Instance Method Details

#find_element(*args) ⇒ WebDriver::Element

Find the first element matching the given arguments.

Parameters:

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

Returns:

Raises:

  • (NoSuchElementError)

    if the element doesn’t exist



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/selenium/webdriver/find.rb', line 28

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

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

  meth = "findElementBy#{by}"
  what = what.to_s

  bridge.send meth, ref, what
end

#find_elements(*args) ⇒ Array<WebDriver::Element>

Find all elements matching the given arguments

Parameters:

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

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/selenium/webdriver/find.rb', line 49

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

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

  meth = "findElementsBy#{by}"
  what = what.to_s

  bridge.send meth, ref, what
end