Skip to content

Commit a72784a

Browse files
authored
fix(test): properly clean input field (#860)
1 parent fa6a5ed commit a72784a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

docs/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,8 @@ const fs = require('fs');
10121012
This method focuses the element and triggers an `input` event after filling.
10131013
If there's no text `<input>`, `<textarea>` or `[contenteditable]` element matching `selector`, the method throws an error.
10141014

1015+
> **NOTE** Pass empty string as a value to clear the input field.
1016+
10151017
Shortcut for [page.mainFrame().fill()](#framefillselector-value)
10161018

10171019
#### page.focus(selector, options)

src/dom.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
414414
}, value);
415415
if (error)
416416
throw new Error(error);
417-
await this._page.keyboard.sendCharacters(value);
417+
if (value)
418+
await this._page.keyboard.sendCharacters(value);
419+
else
420+
await this._page.keyboard.press('Delete');
418421
}
419422

420423
async setInputFiles(...files: (string | types.FilePayload)[]) {

0 commit comments

Comments
 (0)