Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test): properly clean input field (#860)

Andrey Lushnikova72784a67780
diff --git a/docs/api.md b/docs/api.md
index e399429e2f..6a7e5e3180 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -1012,6 +1012,8 @@ const fs = require('fs');
This method focuses the element and triggers an `input` event after filling.
If there's no text `<input>`, `<textarea>` or `[contenteditable]` element matching `selector`, the method throws an error.
+> **NOTE** Pass empty string as a value to clear the input field.
+
Shortcut for [page.mainFrame().fill()](#framefillselector-value)
#### page.focus(selector, options)
diff --git a/src/dom.ts b/src/dom.ts
index e21aa85548..c3d51df735 100644
--- a/src/dom.ts
+++ b/src/dom.ts
@@ -414,7 +414,10 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
}, value);
if (error)
throw new Error(error);
- await this._page.keyboard.sendCharacters(value);
+ if (value)
+ await this._page.keyboard.sendCharacters(value);
+ else
+ await this._page.keyboard.press('Delete');
}
async setInputFiles(...files: (string | types.FilePayload)[]) {