From e81888a5e12c1866f0ad0b431b84e51ed2adc4d9 Mon Sep 17 00:00:00 2001 From: Joshua Fehler Date: Tue, 11 Jun 2024 11:20:50 -0400 Subject: [PATCH] Add keyboard class and Element.press() --- splinter/driver/__init__.py | 17 ++++++++++ splinter/driver/webdriver/__init__.py | 30 +++++++++++++++++ splinter/driver/webdriver/keyboard.py | 47 +++++++++++++++++++++++++++ tests/base.py | 3 +- tests/element.py | 23 +++++++++++++ tests/form_elements.py | 21 +----------- tests/keyboard.py | 13 ++++++++ tests/skip_if.py | 31 ++++++++++++++++++ 8 files changed, 164 insertions(+), 21 deletions(-) create mode 100644 splinter/driver/webdriver/keyboard.py create mode 100644 tests/keyboard.py create mode 100644 tests/skip_if.py diff --git a/splinter/driver/__init__.py b/splinter/driver/__init__.py index a57ea263f..e9714ca23 100644 --- a/splinter/driver/__init__.py +++ b/splinter/driver/__init__.py @@ -871,6 +871,23 @@ def type(self, value: str, slowly: bool = False) -> str: # NOQA: A003 """ raise NotImplementedError + def press(self, key: str, delay: int = 0) -> None: + """Focus the element and press the specified key pattern. + + Key names are case sensitive. + + Arguments: + key_name: Name of the key to press. + delay: Time, in seconds, to wait between key down and key up. + + Example: + + >>> browser.find_by_css('.my_element').press('ENTER') + >>> browser.find_by_css('.my_element').press('SHIFT+awesome') + + """ + raise NotImplementedError + def select(self, value: str, slowly: bool = False) -> None: """ Select an ``