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:
JoelEinbinder
2017-10-07 00:28:24 -07:00
committed by Andrey Lushnikov
parent 0d0f9b7984
commit 0af0d7dba5
6 changed files with 161 additions and 86 deletions

View File

@@ -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 {