Module keyboard_types::webdriver
source ยท 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/
Structsยง
- Store pressed keys and modifiers.
Enumsยง
- Either a
KeyboardEvent
or aCompositionEvent
.
Functionsยง
- code ๐
- get_modifier ๐
- is_shifted_character ๐
- key_location ๐
- normalised_key_value ๐
- Compute the events resulting from a WebDriver Element Send Keys command.