diff --git a/src/injected/injectedScript.ts b/src/injected/injectedScript.ts
index 7acd156efe..c0e0a15b85 100644
--- a/src/injected/injectedScript.ts
+++ b/src/injected/injectedScript.ts
@@ -211,7 +211,7 @@ export default class InjectedScript {
return { status: 'error', error: 'Cannot fill input of type "' + type + '".' };
if (type === 'number') {
value = value.trim();
- if (!value || isNaN(Number(value)))
+ if (isNaN(Number(value)))
return { status: 'error', error: 'Cannot type text into input[type=number].' };
}
if (input.disabled)
diff --git a/test/page.spec.js b/test/page.spec.js
index 93823978a5..d08e947cc5 100644
--- a/test/page.spec.js
+++ b/test/page.spec.js
@@ -1164,16 +1164,15 @@ describe('Page.fill', function() {
await page.fill('input', '-10e5');
expect(await page.evaluate(() => input.value)).toBe('-10e5');
});
- it('should not be able to fill input[type=number] with empty string', async({page}) => {
- await page.setContent(``);
- let error = null;
- await page.fill('input', '').catch(e => error = e);
- expect(error.message).toContain('Cannot type text into input[type=number].');
+ it('should be able to fill input[type=number] with empty string', async({page}) => {
+ await page.setContent(``);
+ await page.fill('input', '');
+ expect(await page.evaluate(() => input.value)).toBe('');
});
it('should not be able to fill text into the input[type=number]', async({page}) => {
await page.setContent(``);
let error = null;
- await page.fill('input', '').catch(e => error = e);
+ await page.fill('input', 'abc').catch(e => error = e);
expect(error.message).toContain('Cannot type text into input[type=number].');
});
it('should be able to clear', async({page, server}) => {