From 1059e22f9ee2a6f17fc1a80d3476ead381a8631c Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Mon, 3 Feb 2020 15:50:45 -0800 Subject: [PATCH] fix(fill): make fill work for input[type=number] (#819) --- src/dom.ts | 11 ++++++++--- test/page.spec.js | 26 ++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/dom.ts b/src/dom.ts index e27572f5e9..5fafbd3730 100644 --- a/src/dom.ts +++ b/src/dom.ts @@ -358,7 +358,7 @@ export class ElementHandle extends js.JSHandle { async fill(value: string): Promise { assert(helper.isString(value), 'Value must be string. Found value "' + value + '" of type "' + (typeof value) + '"'); - const error = await this._evaluateInUtility((node: Node) => { + const error = await this._evaluateInUtility((node: Node, value: string) => { if (node.nodeType !== Node.ELEMENT_NODE) return 'Node is not of type HTMLElement'; const element = node as HTMLElement; @@ -375,9 +375,14 @@ export class ElementHandle extends js.JSHandle { if (element.nodeName.toLowerCase() === 'input') { const input = element as HTMLInputElement; const type = input.getAttribute('type') || ''; - const kTextInputTypes = new Set(['', 'email', 'password', 'search', 'tel', 'text', 'url']); + const kTextInputTypes = new Set(['', 'email', 'number', 'password', 'search', 'tel', 'text', 'url']); if (!kTextInputTypes.has(type.toLowerCase())) return 'Cannot fill input of type "' + type + '".'; + if (type.toLowerCase() === 'number') { + value = value.trim(); + if (!value || isNaN(Number(value))) + return 'Cannot type text into input[type=number].'; + } if (input.disabled) return 'Cannot fill a disabled input.'; if (input.readOnly) @@ -406,7 +411,7 @@ export class ElementHandle extends js.JSHandle { return 'Element is not an ,