Method: Playwright::Keyboard#press
- Defined in:
- lib/playwright_api/keyboard.rb
#press(key, delay: nil) ⇒ Object
NOTE: In most cases, you should use [‘method: Locator.press`] instead.
‘key` can specify the intended [keyboardEvent.key](developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) value or a single character to generate the text for. A superset of the `key` values can be found [here](developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
‘F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`, `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
Following modification shortcuts are also supported: ‘Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`, `ControlOrMeta`. `ControlOrMeta` resolves to `Control` on Windows and Linux and to `Meta` on macOS.
Holding down ‘Shift` will type the text that corresponds to the `key` in the upper case.
If ‘key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective texts.
Shortcuts such as ‘key: “Control+o”`, `key: “Control++` or `key: ”Control+Shift+T“` are supported as well. When specified with the modifier, modifier is pressed and being held while the subsequent key is being pressed.
Usage
“‘python sync page = browser.new_page() page.goto(“keycode.info”) page.keyboard.press(“a”) page.screenshot(path=“a.png”) page.keyboard.press(“ArrowLeft”) page.screenshot(path=“arrow_left.png”) page.keyboard.press(“Shift+O”) page.screenshot(path=“o.png”) browser.close() “`
Shortcut for [‘method: Keyboard.down`] and [`method: Keyboard.up`].
119 120 121 |
# File 'lib/playwright_api/keyboard.rb', line 119 def press(key, delay: nil) wrap_impl(@impl.press(unwrap_impl(key), delay: unwrap_impl(delay))) end |