Skip to content

Commit 45ac40a

Browse files
committed
Refactoring press keys
1 parent ef24f38 commit 45ac40a

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/SeleniumLibrary/keywords/element.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ def press_key(self, locator, key):
845845
def press_keys(self, locator=None, *keys):
846846
"""Simulates the user pressing key(s) to an element or on the active browser.
847847
848-
849848
If ``locator`` evaluates as false, see `Boolean arguments` for more
850849
details, then the ``keys`` are sent to the currently active browser.
851850
Otherwise element is searched and ``keys`` are send to the element
@@ -898,22 +897,18 @@ def press_keys(self, locator=None, *keys):
898897
self._press_keys(locator, parsed_keys)
899898

900899
def _press_keys(self, locator, parsed_keys):
901-
if is_truthy(locator):
902-
element = self.find_element(locator)
903-
else:
904-
element = None
900+
element = self.find_element(locator) if is_truthy(locator) else None
905901
for parsed_key in parsed_keys:
906902
actions = ActionChains(self.driver)
907-
special_keys = []
908903
for key in parsed_key:
909-
if self._selenium_keys_has_attr(key.original):
910-
special_keys = self._press_keys_special_keys(actions, element, parsed_key,
911-
key, special_keys)
904+
if key.special:
905+
self._press_keys_special_keys(actions, element, parsed_key, key)
912906
else:
913907
self._press_keys_normal_keys(actions, element, key)
914-
for special_key in special_keys:
915-
self.info('Releasing special key %s.' % special_key.original)
916-
actions.key_up(special_key.converted)
908+
for key in parsed_key:
909+
if key.special:
910+
self.info('Releasing special key %s.' % key.original)
911+
actions.key_up(key.converted)
917912
actions.perform()
918913

919914
def _press_keys_normal_keys(self, actions, element, key):
@@ -923,7 +918,7 @@ def _press_keys_normal_keys(self, actions, element, key):
923918
else:
924919
actions.send_keys(key.converted)
925920

926-
def _press_keys_special_keys(self, actions, element, parsed_key, key, special_keys):
921+
def _press_keys_special_keys(self, actions, element, parsed_key, key):
927922
if len(parsed_key) == 1 and element:
928923
self.info('Pressing special key %s to element.' % key.original)
929924
actions.send_keys_to_element(element, key.converted)
@@ -933,8 +928,6 @@ def _press_keys_special_keys(self, actions, element, parsed_key, key, special_ke
933928
else:
934929
self.info('Pressing special key %s down.' % key.original)
935930
actions.key_down(key.converted)
936-
special_keys.append(key)
937-
return special_keys
938931

939932
@keyword
940933
def get_all_links(self):

0 commit comments

Comments
 (0)