Method: Selenium::WebDriver::KeyActions#send_keys

Defined in:
lib/selenium/webdriver/common/interactions/key_actions.rb

#send_keys(keys, device: nil) ⇒ ActionBuilder #send_keys(element, keys, device: nil) ⇒ ActionBuilder

Sends keys to the active element. This differs from calling Element#send_keys(keys) on the active element in two ways:

  • The modifier keys included in this call are not released.

  • There is no attempt to re-focus the element - so send_keys(:tab) for switching elements should work.

Examples:

Send the text “help” to an element


el = driver.find_element(id: "some_id")
driver.action.send_keys(el, "help").perform

Send the text “help” to the currently focused element


driver.action.send_keys("help").perform

Overloads:

  • #send_keys(keys, device: nil) ⇒ ActionBuilder

    Parameters:

    • keys (Array, Symbol, String)

      The key(s) to press and release

    • device (Symbol, String) (defaults to: nil)

      Optional name of the KeyInput device to press and release the keys on

  • #send_keys(element, keys, device: nil) ⇒ ActionBuilder

    Parameters:

    • element (Element)

      An optional element to move to first

    • keys (Array, Symbol, String)

      The key(s) to press and release

    • device (Symbol, String) (defaults to: nil)

      Optional name of the KeyInput device to press and release the keys on

Returns:



104
105
106
107
108
109
110
111
# File 'lib/selenium/webdriver/common/interactions/key_actions.rb', line 104

def send_keys(*args, device: nil)
  click(args.shift) if args.first.is_a? Element
  args.map { |x| x.is_a?(String) ? x.chars : x }.flatten.each do |arg|
    key_down(arg, device: device)
    key_up(arg, device: device)
  end
  self
end