Skip to content

Commit 24d4fb1

Browse files
authored
api(click): remove tripleclick, respect clickCount (#1373)
1 parent 8c532bd commit 24d4fb1

File tree

7 files changed

+20
-181
lines changed

7 files changed

+20
-181
lines changed

docs/api.md

-105
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ page.removeListener('request', logRequest);
681681
- [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders)
682682
- [page.setViewportSize(viewportSize)](#pagesetviewportsizeviewportsize)
683683
- [page.title()](#pagetitle)
684-
- [page.tripleclick(selector[, options])](#pagetripleclickselector-options)
685684
- [page.type(selector, text[, options])](#pagetypeselector-text-options)
686685
- [page.uncheck(selector, [options])](#pageuncheckselector-options)
687686
- [page.url()](#pageurl)
@@ -1571,38 +1570,6 @@ await page.goto('https://example.com');
15711570

15721571
Shortcut for [page.mainFrame().title()](#frametitle).
15731572

1574-
#### page.tripleclick(selector[, options])
1575-
- `selector` <[string]> A selector to search for element to triple click. If there are multiple elements satisfying the selector, the first will be triple clicked.
1576-
- `options` <[Object]>
1577-
- `button` <"left"|"right"|"middle"> Defaults to `left`.
1578-
- `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
1579-
- `offset` <[Object]> A point to triple click relative to the top-left corner of element padding box. If not specified, triple clicks to some visible point of the element.
1580-
- x <[number]>
1581-
- y <[number]>
1582-
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the triple click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
1583-
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
1584-
- displayed (for example, no `display:none`),
1585-
- is not moving (for example, waits until css transition finishes),
1586-
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
1587-
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
1588-
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to fire `domcontentloaded` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
1589-
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
1590-
- `'load'` - consider navigation to be finished when the `load` event is fired.
1591-
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
1592-
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
1593-
- `'nowait'` - do not wait.
1594-
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
1595-
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully triple clicked. The Promise will be rejected if there is no element matching `selector`.
1596-
1597-
This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to triple click in the center of the element.
1598-
If there's no element matching `selector`, the method throws an error.
1599-
1600-
Bear in mind that if the first or second click of the `tripleclick()` triggers a navigation event, there will be an exception.
1601-
1602-
> **NOTE** `page.tripleclick()` dispatches three `click` events and a single `dblclick` event.
1603-
1604-
Shortcut for [page.mainFrame().tripleclick(selector[, options])](#frametripleclickselector-options).
1605-
16061573
#### page.type(selector, text[, options])
16071574
- `selector` <[string]> A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
16081575
- `text` <[string]> A text to type into a focused element.
@@ -1917,7 +1884,6 @@ An example of getting text from an iframe element:
19171884
- [frame.selectOption(selector, values[, options])](#frameselectoptionselector-values-options)
19181885
- [frame.setContent(html[, options])](#framesetcontenthtml-options)
19191886
- [frame.title()](#frametitle)
1920-
- [frame.tripleclick(selector[, options])](#frametripleclickselector-options)
19211887
- [frame.type(selector, text[, options])](#frametypeselector-text-options)
19221888
- [frame.uncheck(selector, [options])](#frameuncheckselector-options)
19231889
- [frame.url()](#frameurl)
@@ -2298,36 +2264,6 @@ frame.selectOption('select#colors', { value: 'blue' }, { index: 2 }, 'red');
22982264
#### frame.title()
22992265
- returns: <[Promise]<[string]>> The page's title.
23002266

2301-
#### frame.tripleclick(selector[, options])
2302-
- `selector` <[string]> A selector to search for element to triple click. If there are multiple elements satisfying the selector, the first will be triple clicked.
2303-
- `options` <[Object]>
2304-
- `button` <"left"|"right"|"middle"> Defaults to `left`.
2305-
- `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
2306-
- `offset` <[Object]> A point to triple click relative to the top-left corner of element padding box. If not specified, triple clicks to some visible point of the element.
2307-
- x <[number]>
2308-
- y <[number]>
2309-
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the triple click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
2310-
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
2311-
- displayed (for example, no `display:none`),
2312-
- is not moving (for example, waits until css transition finishes),
2313-
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
2314-
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
2315-
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to fire `domcontentloaded` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
2316-
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
2317-
- `'load'` - consider navigation to be finished when the `load` event is fired.
2318-
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
2319-
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
2320-
- `'nowait'` - do not wait.
2321-
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
2322-
- returns: <[Promise]> Promise which resolves when the element matching `selector` is successfully triple clicked. The Promise will be rejected if there is no element matching `selector`.
2323-
2324-
This method fetches an element with `selector`, scrolls it into view if needed, and then uses [page.mouse](#pagemouse) to triple click in the center of the element.
2325-
If there's no element matching `selector`, the method throws an error.
2326-
2327-
Bear in mind that if the first or second click of the `tripleclick()` triggers a navigation event, there will be an exception.
2328-
2329-
> **NOTE** `frame.tripleclick()` dispatches three `click` events and a single `dblclick` event.
2330-
23312267
#### frame.type(selector, text[, options])
23322268
- `selector` <[string]> A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
23332269
- `text` <[string]> A text to type into a focused element.
@@ -2532,7 +2468,6 @@ ElementHandle instances can be used as arguments in [`page.$eval()`](#pageevalse
25322468
- [elementHandle.selectOption(values[, options])](#elementhandleselectoptionvalues-options)
25332469
- [elementHandle.setInputFiles(files)](#elementhandlesetinputfilesfiles)
25342470
- [elementHandle.toString()](#elementhandletostring)
2535-
- [elementHandle.tripleclick([options])](#elementhandletripleclickoptions)
25362471
- [elementHandle.type(text[, options])](#elementhandletypetext-options)
25372472
- [elementHandle.uncheck([options])](#elementhandleuncheckoptions)
25382473
<!-- GEN:stop -->
@@ -2806,35 +2741,6 @@ Sets the value of the file input to these file paths or files. If some of the `
28062741
#### elementHandle.toString()
28072742
- returns: <[string]>
28082743

2809-
#### elementHandle.tripleclick([options])
2810-
- `options` <[Object]>
2811-
- `button` <"left"|"right"|"middle"> Defaults to `left`.
2812-
- `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
2813-
- `offset` <[Object]> A point to triple click relative to the top-left corner of element padding box. If not specified, triple clicks to some visible point of the element.
2814-
- x <[number]>
2815-
- y <[number]>
2816-
- `modifiers` <[Array]<"Alt"|"Control"|"Meta"|"Shift">> Modifier keys to press. Ensures that only these modifiers are pressed during the triple click, and then restores current modifiers back. If not specified, currently pressed modifiers are used.
2817-
- `force` <[boolean]> Whether to bypass the actionability checks. By default actions wait until the element is:
2818-
- displayed (for example, no `display:none`),
2819-
- is not moving (for example, waits until css transition finishes),
2820-
- receives pointer events at the action point (for example, waits until element becomes non-obscured by other elements).
2821-
Even if the action is forced, it will wait for the element matching selector to be in DOM. Defaults to `false`.
2822-
- `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|"nowait"> Actions that cause navigations are waiting for those navigations to fire `domcontentloaded` by default. This behavior can be changed to either wait for another load phase or to omit the waiting altogether using `nowait`:
2823-
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
2824-
- `'load'` - consider navigation to be finished when the `load` event is fired.
2825-
- `'networkidle0'` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
2826-
- `'networkidle2'` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
2827-
- `'nowait'` - do not wait.
2828-
- `timeout` <[number]> Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browserContext.setDefaultTimeout(timeout)](#browsercontextsetdefaulttimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods.
2829-
- returns: <[Promise]> Promise which resolves when the element is successfully triple clicked. Promise gets rejected if the element is detached from DOM.
2830-
2831-
This method scrolls element into view if needed, and then uses [page.mouse](#pagemouse) to click in the center of the element.
2832-
If the element is detached from DOM, the method throws an error.
2833-
2834-
Bear in mind that if the first or second click of the `tripleclick()` triggers a navigation event, there will be an exception.
2835-
2836-
> **NOTE** `elementHandle.tripleclick()` dispatches three `click` events and a single `dblclick` event.
2837-
28382744
#### elementHandle.type(text[, options])
28392745
- `text` <[string]> A text to type into a focused element.
28402746
- `options` <[Object]>
@@ -3164,7 +3070,6 @@ await page.mouse.up();
31643070
- [mouse.dblclick(x, y[, options])](#mousedblclickx-y-options)
31653071
- [mouse.down([options])](#mousedownoptions)
31663072
- [mouse.move(x, y[, options])](#mousemovex-y-options)
3167-
- [mouse.tripleclick(x, y[, options])](#mousetripleclickx-y-options)
31683073
- [mouse.up([options])](#mouseupoptions)
31693074
<!-- GEN:stop -->
31703075

@@ -3206,16 +3111,6 @@ Dispatches a `mousedown` event.
32063111

32073112
Dispatches a `mousemove` event.
32083113

3209-
#### mouse.tripleclick(x, y[, options])
3210-
- `x` <[number]>
3211-
- `y` <[number]>
3212-
- `options` <[Object]>
3213-
- `button` <"left"|"right"|"middle"> Defaults to `left`.
3214-
- `delay` <[number]> Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
3215-
- returns: <[Promise]>
3216-
3217-
Shortcut for [`mouse.move`](#mousemovex-y-options), [`mouse.down`](#mousedownoptions), [`mouse.up`](#mouseupoptions), [`mouse.down`](#mousedownoptions), [`mouse.up`](#mouseupoptions), [`mouse.down`](#mousedownoptions) and [`mouse.up`](#mouseupoptions).
3218-
32193114
#### mouse.up([options])
32203115
- `options` <[Object]>
32213116
- `button` <"left"|"right"|"middle"> Defaults to `left`.

src/dom.ts

-4
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,6 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
273273
return this._performPointerAction(point => this._page.mouse.dblclick(point.x, point.y, options), options);
274274
}
275275

276-
tripleclick(options?: MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions): Promise<void> {
277-
return this._performPointerAction(point => this._page.mouse.tripleclick(point.x, point.y, options), options);
278-
}
279-
280276
async selectOption(values: string | ElementHandle | types.SelectOption | string[] | ElementHandle[] | types.SelectOption[], options?: types.NavigatingActionWaitOptions): Promise<string[]> {
281277
let vals: string[] | ElementHandle[] | types.SelectOption[];
282278
if (!Array.isArray(values))

src/frames.ts

-6
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,6 @@ export class Frame {
817817
handle.dispose();
818818
}
819819

820-
async tripleclick(selector: string, options?: dom.MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
821-
const handle = await this._waitForSelectorInUtilityContext(selector, options);
822-
await handle.tripleclick(options);
823-
handle.dispose();
824-
}
825-
826820
async fill(selector: string, value: string, options?: types.NavigatingActionWaitOptions) {
827821
const handle = await this._waitForSelectorInUtilityContext(selector, options);
828822
await handle.fill(value, options);

src/input.ts

+18-60
Original file line numberDiff line numberDiff line change
@@ -221,70 +221,28 @@ export class Mouse {
221221
}
222222

223223
async click(x: number, y: number, options: MouseClickOptions = {}) {
224-
const {delay = null} = options;
225-
if (delay !== null) {
226-
await Promise.all([
227-
this.move(x, y),
228-
this.down(options),
229-
]);
230-
await new Promise(f => setTimeout(f, delay));
231-
await this.up(options);
224+
const { delay = null, clickCount = 1 } = options;
225+
if (delay) {
226+
this.move(x, y);
227+
for (let cc = 1; cc <= clickCount; ++cc) {
228+
await this.down({ ...options, clickCount: cc });
229+
await new Promise(f => setTimeout(f, delay));
230+
await this.up({ ...options, clickCount: cc });
231+
if (cc < clickCount)
232+
await new Promise(f => setTimeout(f, delay));
233+
}
232234
} else {
233-
await Promise.all([
234-
this.move(x, y),
235-
this.down(options),
236-
this.up(options),
237-
]);
235+
const promises = [];
236+
promises.push(this.move(x, y));
237+
for (let cc = 1; cc <= clickCount; ++cc) {
238+
promises.push(this.down({ ...options, clickCount: cc }));
239+
promises.push(this.up({ ...options, clickCount: cc }));
240+
}
241+
await Promise.all(promises);
238242
}
239243
}
240244

241245
async dblclick(x: number, y: number, options: MouseMultiClickOptions = {}) {
242-
const { delay = null } = options;
243-
if (delay !== null) {
244-
await this.move(x, y);
245-
await this.down({ ...options, clickCount: 1 });
246-
await new Promise(f => setTimeout(f, delay));
247-
await this.up({ ...options, clickCount: 1 });
248-
await new Promise(f => setTimeout(f, delay));
249-
await this.down({ ...options, clickCount: 2 });
250-
await new Promise(f => setTimeout(f, delay));
251-
await this.up({ ...options, clickCount: 2 });
252-
} else {
253-
await Promise.all([
254-
this.move(x, y),
255-
this.down({ ...options, clickCount: 1 }),
256-
this.up({ ...options, clickCount: 1 }),
257-
this.down({ ...options, clickCount: 2 }),
258-
this.up({ ...options, clickCount: 2 }),
259-
]);
260-
}
261-
}
262-
263-
async tripleclick(x: number, y: number, options: MouseMultiClickOptions = {}) {
264-
const { delay = null } = options;
265-
if (delay !== null) {
266-
await this.move(x, y);
267-
await this.down({ ...options, clickCount: 1 });
268-
await new Promise(f => setTimeout(f, delay));
269-
await this.up({ ...options, clickCount: 1 });
270-
await new Promise(f => setTimeout(f, delay));
271-
await this.down({ ...options, clickCount: 2 });
272-
await new Promise(f => setTimeout(f, delay));
273-
await this.up({ ...options, clickCount: 2 });
274-
await new Promise(f => setTimeout(f, delay));
275-
await this.down({ ...options, clickCount: 3 });
276-
await new Promise(f => setTimeout(f, delay));
277-
await this.up({ ...options, clickCount: 3 });
278-
} else {
279-
await Promise.all([
280-
this.move(x, y),
281-
this.down({ ...options, clickCount: 1 }),
282-
this.up({ ...options, clickCount: 1 }),
283-
this.down({ ...options, clickCount: 2 }),
284-
this.up({ ...options, clickCount: 2 }),
285-
this.down({ ...options, clickCount: 3 }),
286-
this.up({ ...options, clickCount: 3 }),
287-
]);
288-
}
246+
await this.click(x, y, { ...options, clickCount: 2 });
289247
}
290248
}

src/page.ts

-4
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,6 @@ export class Page extends platform.EventEmitter {
468468
return this.mainFrame().dblclick(selector, options);
469469
}
470470

471-
async tripleclick(selector: string, options?: dom.MultiClickOptions & types.PointerActionWaitOptions & types.NavigatingActionWaitOptions) {
472-
return this.mainFrame().tripleclick(selector, options);
473-
}
474-
475471
async fill(selector: string, value: string, options?: types.NavigatingActionWaitOptions) {
476472
return this.mainFrame().fill(selector, value, options);
477473
}

test/click.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ module.exports.describe = function({testRunner, expect, playwright, FFOX, CHROMI
110110
await page.goto(server.PREFIX + '/input/textarea.html');
111111
const text = 'This is the text that we are going to try to select. Let\'s see how it goes.';
112112
await page.fill('textarea', text);
113-
await page.tripleclick('textarea');
113+
await page.click('textarea', { clickCount: 3 });
114114
expect(await page.evaluate(() => {
115115
const textarea = document.querySelector('textarea');
116116
return textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);

test/navigation.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ module.exports.describe = function({testRunner, expect, playwright, MAC, WIN, FF
982982
await page.setContent(`<a href='${httpsServer.EMPTY_PAGE}'>foobar</a>`);
983983
await page.click('a');
984984
});
985-
it('clicking on download link', async({page, server, httpsServer}) => {
985+
it.fail(FFOX)('clicking on download link', async({page, server, httpsServer}) => {
986986
await page.setContent(`<a href="${server.PREFIX}/wasm/table2.wasm" download=true>table2.wasm</a>`);
987987
await page.click('a');
988988
});

0 commit comments

Comments
 (0)