Родитель
e1d3196460
Коммит
8c532bd8da
12
docs/api.md
12
docs/api.md
|
@ -1399,7 +1399,6 @@ The `format` options are:
|
||||||
- `selector` <[string]> A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
|
- `selector` <[string]> A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
|
||||||
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
- `text` <[string]> If specified, generates an input event with this text.
|
|
||||||
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
||||||
- `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`:
|
- `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`:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
|
@ -2236,7 +2235,6 @@ If the name is empty, returns the id attribute instead.
|
||||||
- `selector` <[string]> A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
|
- `selector` <[string]> A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
|
||||||
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
- `text` <[string]> If specified, generates an input event with this text.
|
|
||||||
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
||||||
- `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`:
|
- `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`:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
|
@ -2727,7 +2725,6 @@ If the element is detached from DOM, the method throws an error.
|
||||||
#### elementHandle.press(key[, options])
|
#### elementHandle.press(key[, options])
|
||||||
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
- `text` <[string]> If specified, generates an input event with this text.
|
|
||||||
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
||||||
- `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`:
|
- `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`:
|
||||||
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
- `'domcontentloaded'` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
||||||
|
@ -3077,22 +3074,20 @@ await page.keyboard.up('Shift');
|
||||||
> **NOTE** On MacOS, keyboard shortcuts like `⌘ A` -> Select All do not work. See [#1313](https://github.com/GoogleChrome/puppeteer/issues/1313)
|
> **NOTE** On MacOS, keyboard shortcuts like `⌘ A` -> Select All do not work. See [#1313](https://github.com/GoogleChrome/puppeteer/issues/1313)
|
||||||
|
|
||||||
<!-- GEN:toc -->
|
<!-- GEN:toc -->
|
||||||
- [keyboard.down(key[, options])](#keyboarddownkey-options)
|
- [keyboard.down(key)](#keyboarddownkey)
|
||||||
- [keyboard.insertText(text)](#keyboardinserttexttext)
|
- [keyboard.insertText(text)](#keyboardinserttexttext)
|
||||||
- [keyboard.press(key[, options])](#keyboardpresskey-options)
|
- [keyboard.press(key[, options])](#keyboardpresskey-options)
|
||||||
- [keyboard.type(text[, options])](#keyboardtypetext-options)
|
- [keyboard.type(text[, options])](#keyboardtypetext-options)
|
||||||
- [keyboard.up(key)](#keyboardupkey)
|
- [keyboard.up(key)](#keyboardupkey)
|
||||||
<!-- GEN:stop -->
|
<!-- GEN:stop -->
|
||||||
|
|
||||||
#### keyboard.down(key[, options])
|
#### keyboard.down(key)
|
||||||
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
||||||
- `options` <[Object]>
|
|
||||||
- `text` <[string]> If specified, generates an input event with this text.
|
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
Dispatches a `keydown` event.
|
Dispatches a `keydown` event.
|
||||||
|
|
||||||
If `key` is a single character and no modifier keys besides `Shift` are being held down, a `keypress`/`input` event will also generated. The `text` option can be specified to force an input event to be generated.
|
If `key` is a single character and no modifier keys besides `Shift` are being held down, a `keypress`/`input` event will also generated.
|
||||||
|
|
||||||
If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that modifier active. To release the modifier key, use [`keyboard.up`](#keyboardupkey).
|
If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that modifier active. To release the modifier key, use [`keyboard.up`](#keyboardupkey).
|
||||||
|
|
||||||
|
@ -3115,7 +3110,6 @@ page.keyboard.insertText('嗨');
|
||||||
#### keyboard.press(key[, options])
|
#### keyboard.press(key[, options])
|
||||||
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
- `key` <[string]> Name of key to press, such as `ArrowLeft`. See [USKeyboardLayout] for a list of all key names.
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
- `text` <[string]> If specified, generates an input event with this text.
|
|
||||||
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
- `delay` <[number]> Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0.
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
}, options, true);
|
}, options, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async press(key: string, options?: { delay?: number, text?: string } & types.NavigatingActionWaitOptions) {
|
async press(key: string, options?: { delay?: number } & types.NavigatingActionWaitOptions) {
|
||||||
await this._page._frameManager.waitForNavigationsCreatedBy(async () => {
|
await this._page._frameManager.waitForNavigationsCreatedBy(async () => {
|
||||||
await this.focus();
|
await this.focus();
|
||||||
await this._page.keyboard.press(key, options);
|
await this._page.keyboard.press(key, options);
|
||||||
|
|
|
@ -854,7 +854,7 @@ export class Frame {
|
||||||
handle.dispose();
|
handle.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
async press(selector: string, key: string, options?: { delay?: number, text?: string } & types.NavigatingActionWaitOptions) {
|
async press(selector: string, key: string, options?: { delay?: number } & types.NavigatingActionWaitOptions) {
|
||||||
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
const handle = await this._waitForSelectorInUtilityContext(selector, options);
|
||||||
await handle.press(key, options);
|
await handle.press(key, options);
|
||||||
handle.dispose();
|
handle.dispose();
|
||||||
|
|
11
src/input.ts
11
src/input.ts
|
@ -59,13 +59,13 @@ export class Keyboard {
|
||||||
this._raw = raw;
|
this._raw = raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
async down(key: string, options: { text?: string; } = { text: undefined }) {
|
async down(key: string) {
|
||||||
const description = this._keyDescriptionForString(key);
|
const description = this._keyDescriptionForString(key);
|
||||||
const autoRepeat = this._pressedKeys.has(description.code);
|
const autoRepeat = this._pressedKeys.has(description.code);
|
||||||
this._pressedKeys.add(description.code);
|
this._pressedKeys.add(description.code);
|
||||||
if (kModifiers.includes(description.key as Modifier))
|
if (kModifiers.includes(description.key as Modifier))
|
||||||
this._pressedModifiers.add(description.key as Modifier);
|
this._pressedModifiers.add(description.key as Modifier);
|
||||||
const text = options.text === undefined ? description.text : options.text;
|
const text = description.text;
|
||||||
await this._raw.keydown(this._pressedModifiers, description.code, description.keyCode, description.keyCodeWithoutLocation, description.key, description.location, autoRepeat, text);
|
await this._raw.keydown(this._pressedModifiers, description.code, description.keyCode, description.keyCodeWithoutLocation, description.key, description.location, autoRepeat, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +143,9 @@ export class Keyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async press(key: string, options: { delay?: number; text?: string; } = {}) {
|
async press(key: string, options: { delay?: number } = {}) {
|
||||||
const {delay = null} = options;
|
await this.down(key);
|
||||||
await this.down(key, options);
|
if (options.delay)
|
||||||
if (delay)
|
|
||||||
await new Promise(f => setTimeout(f, options.delay));
|
await new Promise(f => setTimeout(f, options.delay));
|
||||||
await this.up(key);
|
await this.up(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -492,7 +492,7 @@ export class Page extends platform.EventEmitter {
|
||||||
return this.mainFrame().type(selector, text, options);
|
return this.mainFrame().type(selector, text, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async press(selector: string, key: string, options?: { delay?: number, text?: string } & types.NavigatingActionWaitOptions) {
|
async press(selector: string, key: string, options?: { delay?: number } & types.NavigatingActionWaitOptions) {
|
||||||
return this.mainFrame().press(selector, key, options);
|
return this.mainFrame().press(selector, key, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,6 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT,
|
||||||
await textarea.press('b');
|
await textarea.press('b');
|
||||||
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('a');
|
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('a');
|
||||||
});
|
});
|
||||||
it('ElementHandle.press should support |text| option', async({page, server}) => {
|
|
||||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
|
||||||
const textarea = await page.$('textarea');
|
|
||||||
await textarea.press('a', {text: 'ё'});
|
|
||||||
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('ё');
|
|
||||||
});
|
|
||||||
it('should send a character with sendCharacter', async({page, server}) => {
|
it('should send a character with sendCharacter', async({page, server}) => {
|
||||||
await page.goto(server.PREFIX + '/input/textarea.html');
|
await page.goto(server.PREFIX + '/input/textarea.html');
|
||||||
await page.focus('textarea');
|
await page.focus('textarea');
|
||||||
|
|
Загрузка…
Ссылка в новой задаче