Expand description

Keyboard related WebDriver functionality.

The low-level dispatch_keydown and 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::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/


Store pressed keys and modifiers.


Either a KeyboardEvent or a CompositionEvent.


code 🔒

Spec: https://w3c.github.io/webdriver/#dfn-code

Compute the events resulting from a WebDriver Element Send Keys command.