Skip to content

Commit d19773a

Browse files
committed
Removed deprecation of Press Key keyword
Reverted keyword documentation on `Press Key`. Also added note telling about the differing underlying methods and to try the other if the one used does not work.
1 parent cafc0b4 commit d19773a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/SeleniumLibrary/keywords/element.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,26 @@ def simulate_event(self, locator: Union[WebElement, str], event: str):
899899

900900
@keyword
901901
def press_key(self, locator: Union[WebElement, str], key: str):
902-
"""*DEPRECATED in SeleniumLibrary 4.0.* use `Press Keys` instead."""
902+
"""Simulates user pressing key on element identified by ``locator``.
903+
904+
See the `Locating elements` section for details about the locator
905+
syntax.
906+
907+
``key`` is either a single character, a string, or a numerical ASCII
908+
code of the key lead by '\\'.
909+
910+
Examples:
911+
| `Press Key` | text_field | q |
912+
| `Press Key` | text_field | abcde |
913+
| `Press Key` | login_button | \\13 | # ASCII code for enter key |
914+
915+
`Press Key` and `Press Keys` differ in the methods to simulate key
916+
presses. `Press Key` uses the WebDriver `SEND_KEYS_TO_ELEMENT` command
917+
using the selenium send_keys method. Although one is not recommended
918+
over the other if `Press Key` does not work we recommend trying
919+
`Press Keys`.
920+
send_
921+
"""
903922
if key.startswith("\\") and len(key) > 1:
904923
key = self._map_ascii_key_code_to_key(int(key[1:]))
905924
element = self.find_element(locator)
@@ -952,6 +971,13 @@ def press_keys(self, locator: Union[WebElement, None, str] = None, *keys: str):
952971
| `Press Keys` | text_field | ALT | ARROW_DOWN | # Pressing "ALT" key and then pressing ARROW_DOWN. |
953972
| `Press Keys` | text_field | CTRL+c | | # Pressing CTRL key down, sends string "c" and then releases CTRL key. |
954973
| `Press Keys` | button | RETURN | | # Pressing "ENTER" key to element. |
974+
975+
`Press Key` and `Press Keys` differ in the methods to simulate key
976+
presses. `Press Keys` uses the Selenium/WebDriver Actions.
977+
`Press Keys` also has a more extensive syntax for describing keys,
978+
key combinations, and key actions. Although one is not recommended
979+
over the other if `Press Keys` does not work we recommend trying
980+
`Press Key`.
955981
"""
956982
parsed_keys = self._parse_keys(*keys)
957983
if not is_noney(locator):

0 commit comments

Comments
 (0)