Source code for selenium.webdriver.common.actions.key_input

# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from . import interaction
from .input_device import InputDevice
from .interaction import Interaction
from .interaction import Pause

[docs]class KeyInput(InputDevice): def __init__(self, name: str) -> None: super().__init__() = name self.type = interaction.KEY
[docs] def encode(self) -> dict: return {"type": self.type, "id":, "actions": [acts.encode() for acts in self.actions]}
[docs] def create_key_down(self, key) -> None: self.add_action(TypingInteraction(self, "keyDown", key))
[docs] def create_key_up(self, key) -> None: self.add_action(TypingInteraction(self, "keyUp", key))
[docs] def create_pause(self, pause_duration: float = 0) -> None: self.add_action(Pause(self, pause_duration))
[docs]class TypingInteraction(Interaction): def __init__(self, source, type_, key) -> None: super().__init__(source) self.type = type_ self.key = key
[docs] def encode(self) -> dict: return {"type": self.type, "value": self.key}