mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(Input): Add keyboard methods to elementHandle (#801)
This patch: - adds input methods to ElementHandle, such as ElementHandle.type and ElementHandle.press - changes `page.type` to accept selector as the first argument - removes `page.press` method. The `page.press` is rarely used and doesn't operate with selectors; if there's a need to press a button, `page.keyboard.press` should be used. BREAKING CHANGE: `page.type` is changed, `page.press` is removed. Fixes #241.
This commit is contained in:
committed by
Andrey Lushnikov
parent
0d0f9b7984
commit
0af0d7dba5
26
lib/Input.js
26
lib/Input.js
@@ -88,6 +88,32 @@ class Keyboard {
|
||||
unmodifiedText: char
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {{delay: (number|undefined)}=} options
|
||||
*/
|
||||
async type(text, options) {
|
||||
let delay = 0;
|
||||
if (options && options.delay)
|
||||
delay = options.delay;
|
||||
for (const char of text) {
|
||||
await this.press(char, {text: char, delay});
|
||||
if (delay)
|
||||
await new Promise(f => setTimeout(f, delay));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {!Object=} options
|
||||
*/
|
||||
async press(key, options) {
|
||||
await this.down(key, options);
|
||||
if (options && options.delay)
|
||||
await new Promise(f => setTimeout(f, options.delay));
|
||||
await this.up(key);
|
||||
}
|
||||
}
|
||||
|
||||
class Mouse {
|
||||
|
||||
Reference in New Issue
Block a user