Skip to content

Commit 1dddaef

Browse files
committed
[js] Change sendKeys() to officially accept numbers as inputs (values are still
converted to string as required by the wire protocol). sendKeys will throw if a type other than string/number is provided. Fixes #2211
1 parent a494a3a commit 1dddaef

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,22 +1911,24 @@ class WebElement {
19111911
* punctionation keys will be synthesized according to a standard QWERTY en-us
19121912
* keyboard layout.
19131913
*
1914-
* @param {...(string|!promise.Promise<string>)} var_args The
1915-
* sequence of keys to type. All arguments will be joined into a single
1914+
* @param {...(number|string|!IThenable<(number|string)>)} var_args The
1915+
* sequence of keys to type. Number keys may be referenced numerically or
1916+
* by string (1 or '1'). All arguments will be joined into a single
19161917
* sequence.
19171918
* @return {!promise.Promise<void>} A promise that will be resolved
19181919
* when all keys have been typed.
19191920
*/
19201921
sendKeys(var_args) {
1921-
// Coerce every argument to a string. This protects us from users that
1922-
// ignore the jsdoc and give us a number (which ends up causing problems on
1923-
// the server, which requires strings).
19241922
let keys = Promise.all(Array.prototype.slice.call(arguments, 0)).
19251923
then(keys => {
19261924
let ret = [];
19271925
keys.forEach(key => {
1928-
if (typeof key !== 'string') {
1926+
let type = typeof key;
1927+
if (type === 'number') {
19291928
key = String(key);
1929+
} else if (type !== 'string') {
1930+
throw TypeError(
1931+
'each key must be a number of string; got ' + type);
19301932
}
19311933

19321934
// The W3C protocol requires keys to be specified as an array where
@@ -1935,6 +1937,7 @@ class WebElement {
19351937
});
19361938
return ret;
19371939
});
1940+
19381941
if (!this.driver_.fileDetector_) {
19391942
return this.schedule_(
19401943
new command.Command(command.Name.SEND_KEYS_TO_ELEMENT).

0 commit comments

Comments
 (0)