Expand description
Keyboard related WebDriver functionality.
The low-level KeyInputState::dispatch_keydown
and
KeyInputState::dispatch_keyup
API creates keyboard events
from WebDriver codes. It is used in the Perform Actions API.
let mut state = KeyInputState::new();
let mut keyboard_event = state.dispatch_keydown('a');
assert_eq!(keyboard_event.state, KeyState::Down);
assert_eq!(keyboard_event.key, Key::Character("a".to_owned()));
assert_eq!(keyboard_event.code, Code::KeyA);
// The `\u{E029}` code is the WebDriver id for the Numpad divide key.
keyboard_event = state.dispatch_keydown('\u{E050}');
assert_eq!(keyboard_event.key, Key::Named(NamedKey::Shift));
assert_eq!(keyboard_event.code, Code::ShiftRight);
assert_eq!(keyboard_event.location, Location::Right);
keyboard_event = state.dispatch_keyup('\u{E050}').expect("key is released");
keyboard_event = state.dispatch_keyup('a').expect("key is released");
The higher level send_keys
function is used for the Element Send Keys
WebDriver API. It accepts a string and returns a sequence of KeyboardEvent
and CompositionEvent
values.
let events = send_keys("Hello world!\u{E006}");
println!("{:#?}", events);
let events = send_keys("A\u{0308}");
println!("{:#?}", events);
Specification: https://w3c.github.io/webdriver/
Structsยง
- KeyInput
State - Store pressed keys and modifiers.
Enumsยง
- Event
- Either a
KeyboardEvent
or aCompositionEvent
.
Functionsยง
- code ๐
- Spec: https://w3c.github.io/webdriver/#dfn-code
- get_
modifier ๐ - is_
shifted_ ๐character - key_
location ๐ - normalised_
key_ ๐value - send_
keys - Compute the events resulting from a WebDriver Element Send Keys command.