Skip to content

Commit d33bb2a

Browse files
committed
clear() method overload
1 parent 7f68922 commit d33bb2a

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

source/puppeteer/lib/ElementHandle.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ try {
99
Super = require('puppeteer-core/lib/cjs/puppeteer/common/JSHandle').ElementHandle;
1010
}
1111

12+
Super.prototype.clear = function () {
13+
return this.click({ clickCount: 3 }).then(() => this.press('Backspace'));
14+
};
15+
1216
Super.prototype.clickAndWaitForNavigation = function (options?: WaitForOptions) {
1317
options = options ?? {
1418
waitUntil: [

source/puppeteer/lib/FrameManager.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ try {
99
Super = require('puppeteer-core/lib/cjs/puppeteer/common/FrameManager').Frame;
1010
}
1111

12+
Super.prototype.clear = function (selector: string) {
13+
return this.$(selector).then((element) => element?.clear());
14+
};
15+
1216
Super.prototype.clickAndWaitForNavigation = function (selector: string, options?: WaitForOptions) {
1317
options = options ?? {
1418
waitUntil: [

source/puppeteer/lib/Page.ts

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Super.prototype.block = function (predicates: string[]) {
1515
});
1616
};
1717

18+
Super.prototype.clear = function (selector: string) {
19+
return this.mainFrame().clear(selector);
20+
};
21+
1822
Super.prototype.clickAndWaitForNavigation = function (selector: string, options?: WaitForOptions) {
1923
return this.mainFrame().clickAndWaitForNavigation(selector, options);
2024
};

typings/chrome-aws-lambda.d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ declare module 'puppeteer-core' {
3939
}
4040

4141
interface ElementHandle {
42+
/**
43+
* Selects all text in a editable element and clears it.
44+
*/
45+
clear(): Promise<void>;
46+
4247
/**
4348
* Clicks an element and waits for navigation to finish.
4449
*
@@ -140,6 +145,13 @@ declare module 'puppeteer-core' {
140145
}
141146

142147
interface Frame {
148+
/**
149+
* Selects all text in a editable element and clears it.
150+
*
151+
* @param selector - Selector to query for.
152+
*/
153+
clear(selector: string): Promise<void>;
154+
143155
/**
144156
* Clicks an element and waits for navigation to finish.
145157
*
@@ -289,6 +301,13 @@ declare module 'puppeteer-core' {
289301
*/
290302
block(patterns: string[]): Promise<void>;
291303

304+
/**
305+
* Selects all text in a editable element and clears it.
306+
*
307+
* @param selector - Selector to query for.
308+
*/
309+
clear(selector: string): Promise<void>;
310+
292311
/**
293312
* Clicks an element and waits for navigation to finish.
294313
*

0 commit comments

Comments
 (0)