Skip to content

Commit

Permalink
[js] Change sendKeys() to officially accept numbers as inputs (values…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
jleyba committed Jun 12, 2016
1 parent a494a3a commit 1dddaef
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1911,22 +1911,24 @@ class WebElement {
* punctionation keys will be synthesized according to a standard QWERTY en-us
* keyboard layout.
*
* @param {...(string|!promise.Promise<string>)} var_args The
* sequence of keys to type. All arguments will be joined into a single
* @param {...(number|string|!IThenable<(number|string)>)} var_args The
* sequence of keys to type. Number keys may be referenced numerically or
* by string (1 or '1'). All arguments will be joined into a single
* sequence.
* @return {!promise.Promise<void>} A promise that will be resolved
* when all keys have been typed.
*/
sendKeys(var_args) {
// Coerce every argument to a string. This protects us from users that
// ignore the jsdoc and give us a number (which ends up causing problems on
// the server, which requires strings).
let keys = Promise.all(Array.prototype.slice.call(arguments, 0)).
then(keys => {
let ret = [];
keys.forEach(key => {
if (typeof key !== 'string') {
let type = typeof key;
if (type === 'number') {
key = String(key);
} else if (type !== 'string') {
throw TypeError(
'each key must be a number of string; got ' + type);
}

// The W3C protocol requires keys to be specified as an array where
Expand All @@ -1935,6 +1937,7 @@ class WebElement {
});
return ret;
});

if (!this.driver_.fileDetector_) {
return this.schedule_(
new command.Command(command.Name.SEND_KEYS_TO_ELEMENT).
Expand Down

0 comments on commit 1dddaef

Please sign in to comment.