Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/injected/src/injectedScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,13 @@ export class InjectedScript {
value = value.trim();
input.focus();
input.value = value;
// The browser serializes range values in canonical form, e.g. "0.850" becomes "0.85".
const accepted = type === 'range' ? Number(input.value) === Number(value) : input.value === value;
// The browser serializes some values in canonical form, e.g. range "0.850" becomes "0.85" and
// datetime-local "2020-03-02T05:15:00" becomes "2020-03-02T05:15". Invalid datetime-local values become "".
let accepted = input.value === value;
if (!accepted && type === 'range')
accepted = Number(input.value) === Number(value);
else if (!accepted && type === 'datetime-local')
accepted = !!input.value;
Comment thread
yury-s marked this conversation as resolved.
Resolved
if (!accepted)
throw this.createStacklessError('Malformed value');
element.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
Expand Down
7 changes: 6 additions & 1 deletion tests/page/page-fill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,15 @@ it('should throw on incorrect time', async ({ page, browserName }) => {
expect(error.message).toContain('Malformed value');
});

it('should fill datetime-local input', async ({ page, server }) => {
it('should fill datetime-local input', {
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43370' },
}, async ({ page, server }) => {
await page.setContent('<input type=datetime-local>');
await page.fill('input', '2020-03-02T05:15');
expect(await page.$eval('input', input => input.value)).toBe('2020-03-02T05:15');
// The browser omits zero seconds.
await page.fill('input', '2020-03-02T06:20:00');
expect(await page.$eval('input', input => input.value)).toBe('2020-03-02T06:20');
});

it('should throw on incorrect datetime-local', async ({ page, server, browserName }) => {
Expand Down