Mouse & Keyboard
Mouse
page.mouse
scroll_to(x, y)
Scroll page to a given x, y
- x
Integerthe pixel along the horizontal axis of the document that you want displayed in the upper left - y
Integerthe pixel along the vertical axis of the document that you want displayed in the upper left
page.go_to("https://www.google.com/search?q=Ruby+headless+driver+for+Capybara")
page.mouse.scroll_to(0, 400)
click(**options) : Mouse
Click given coordinates, fires mouse move, down and up events.
- options
Hash- :x
Integer - :y
Integer - :delay
Floatdefaults to 0. Delay between mouse down and mouse up events - :button
Symbol:left | :right, defaults to :left - :count
Integerdefaults to 1 - :modifiers
Integerbitfield for key modifiers. Seekeyboard.modifiers
- :x
down(**options) : Mouse
Mouse down for given coordinates.
- options
Hash- :button
Symbol:left | :right, defaults to :left - :count
Integerdefaults to 1 - :modifiers
Integerbitfield for key modifiers. Seekeyboard.modifiers
- :button
up(**options) : Mouse
Mouse up for given coordinates.
- options
Hash- :button
Symbol:left | :right, defaults to :left - :count
Integerdefaults to 1 - :modifiers
Integerbitfield for key modifiers. Seekeyboard.modifiers
- :button
move(x:, y:, steps: 1) : Mouse
Mouse move to given x and y.
- options
Hash- :x
Integer - :y
Integer - :steps
Integerdefaults to 1. Sends intermediate mousemove events.
- :x
Keyboard
page.keyboard
down(key) : Keyboard
Dispatches a keydown event.
- key
String|SymbolName of key such as "a", :enter, :backspace
up(key) : Keyboard
Dispatches a keyup event.
- key
String|SymbolName of key such as "b", :enter, :backspace
type(*keys) : Keyboard
Sends a keydown, keypress/input, and keyup event for each character in the text.
- text
String|Array<String> | Array<Symbol>A text to type into a focused element,[:Shift, "s"], "tring"
modifiers(keys) : Integer
Returns bitfield for a given keys
- keys
Array<Symbol>:alt | :ctrl | :command | :shift
Examples
# Type text into an input
page.go_to("https://google.com")
input = page.at_css("input[name='q']")
input.focus
page.keyboard.type("Hello World")
# Press Enter
page.keyboard.type(:Enter)
# Use keyboard shortcuts
page.keyboard.down(:Shift)
page.keyboard.type("h", "e", "l", "l", "o")
page.keyboard.up(:Shift)