Implement basic element handles (#248)

This patch implements basic element handles which a backed with remote objects.

Fixes #111
This commit is contained in:
Andrey Lushnikov
2017-08-15 14:54:02 -07:00
committed by GitHub
parent a424f5613a
commit af89e893e7
7 changed files with 299 additions and 81 deletions

View File

@@ -138,6 +138,14 @@ class Page extends EventEmitter {
});
}
/**
* @param {string} selector
* @return {!Promise<?ElementHandle>}
*/
async $(selector) {
return this.mainFrame().$(selector);
}
/**
* @param {string} url
* @return {!Promise}
@@ -555,7 +563,10 @@ class Page extends EventEmitter {
* @return {!Promise}
*/
async click(selector, options) {
await this.mainFrame().click(selector, options);
let handle = await this.$(selector);
console.assert(handle, 'No node found for selector: ' + selector);
await handle.click(options);
await handle.release();
}
/**
@@ -563,7 +574,10 @@ class Page extends EventEmitter {
* @param {!Promise}
*/
async hover(selector) {
await this.mainFrame().hover(selector);
let handle = await this.$(selector);
console.assert(handle, 'No node found for selector: ' + selector);
await handle.hover();
await handle.release();
}
/**
@@ -571,7 +585,10 @@ class Page extends EventEmitter {
* @return {!Promise}
*/
async focus(selector) {
return this.mainFrame().focus(selector);
let handle = await this.$(selector);
console.assert(handle, 'No node found for selector: ' + selector);
await handle.evaluate(element => element.focus());
await handle.release();
}
/**