@@ -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 )
0 commit comments