Skip to content

Commit 46c052e

Browse files
committed
Fixes suggested by pekka
1 parent d1f592e commit 46c052e

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/Selenium2Library/keywords/_element.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -479,29 +479,23 @@ def simulate(self, locator, event):
479479
def press_key(self, locator, key):
480480
"""Simulates user pressing key on element identified by `locator`.
481481
482-
`key` is either a single character, a numerical ASCII code of the key,\
482+
`key` is either a single character, a numerical ASCII code of the key lead by '\\\\',
483483
or a NAMED KEY as described at https://selenium.googlecode.com/git/docs/api/py/webdriver/selenium.webdriver.common.keys.html
484484
485485
Examples:
486-
| Press Key | text_field | q | |
487-
| Press Key | login_button | \\\\13 | # ASCII code for Enter key (DEPRECATED) |
488-
| Press Key | login_button | 10 | # ASCII code for Return key |
486+
| Press Key | text_field | q | # The letter 'q' |
487+
| Press Key | login_button | \\\\13 | # ASCII code for Enter key |
489488
| Press Key | nav_console | ARROW_UP | # selenium.webdriver.common.keys ARROW_UP KEY |
490-
489+
491490
NAMED KEY value is new in Selenium2Library 1.7.3.
492491
"""
493492
if len(key) > 1:
494493
if key.startswith('\\'):
495-
self._warn("Press Key: Escaped ASCII codes are deprecated. Use plain numeric value: '%s'" % (key[1:]))
496494
key = self._map_ascii_key_code_to_key(int(key[1:]))
497495
else:
498-
try:
499-
key = (key.isdecimal() and self._map_ascii_key_code_to_key(int(key))) or\
500-
((not key.isdecimal()) and self._map_named_key_code_to_special_key(key))
501-
except:
502-
raise ValueError("Key value '%s' is invalid." % (key))
496+
key = self._map_named_key_code_to_special_key(key)
503497
element = self._element_find(locator, True, True)
504-
#select it
498+
# select it
505499
element.send_keys(key)
506500

507501
# Public, links
@@ -609,7 +603,7 @@ def get_matching_xpath_count(self, xpath):
609603
"""Returns number of elements matching `xpath`
610604
611605
One should not use the xpath= prefix for 'xpath'. XPath is assumed.
612-
606+
613607
Correct:
614608
| count = | Get Matching Xpath Count | //div[@id='sales-pop']
615609
Incorrect:
@@ -625,7 +619,7 @@ def xpath_should_match_x_times(self, xpath, expected_xpath_count, message='', lo
625619
"""Verifies that the page contains the given number of elements located by the given `xpath`.
626620
627621
One should not use the xpath= prefix for 'xpath'. XPath is assumed.
628-
622+
629623
Correct:
630624
| Xpath Should Match X Times | //div[@id='sales-pop'] | 1
631625
Incorrect:
@@ -761,7 +755,7 @@ def _map_ascii_key_code_to_key(self, key_code):
761755
def _map_named_key_code_to_special_key(self, key_name):
762756
try:
763757
return getattr(Keys, key_name)
764-
except:
758+
except AttributeError:
765759
message = "Unknown key named '%s'." % (key_name)
766760
self._debug(message)
767761
raise ValueError(message)

test/acceptance/keywords/textfields.robot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Get Value From Text Field
1111
Clear Element Text name
1212
${text} = Get Value name
1313
Should Be Equal ${text} ${EMPTY}
14-
14+
1515

1616
Input Unicode In Text Field
1717
Input Text name ${unic_text}
@@ -38,13 +38,13 @@ Press Key
3838
Press Key username_field DELETE
3939
Press Key username_field ARROW_LEFT
4040
Press Key username_field ARROW_RIGHT
41-
Press Key username_field \\108 #This is the 'l' char (deprecated style)
42-
Press Key username_field 111 #This is the 'o' char
41+
Press Key username_field \\108 #This is the 'l' char
42+
Press Key username_field o
4343
${text} = Get Value username_field
4444
Should Be Equal ${text} James Blond
4545
Press Key password_field f
4646
Press Key password_field 9
47-
Press Key login_button 10
47+
Press Key login_button ENTER
4848
Verify Location Is "forms/submit.html"
4949

5050
Attempt Clear Element Text On Non-Editable Field

0 commit comments

Comments
 (0)