diff --git a/docs/api.md b/docs/api.md index 85cf77b52b..463f99a319 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1277,7 +1277,7 @@ await browser.close(); #### page.select(selector, value, options) - `selector` <[string]> A selector to query frame for. -- `value` <[string]|[ElementHandle]|[Array]<[string]>|[Object]|[Array]<[ElementHandle]>|[Array]<[Object]>> Options to select. If the `` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option is considered matching if all specified properties match. - `value` <[string]> Matches by `option.value`. - `label` <[string]> Matches by `option.label`. - `index` <[number]> Matches by the index. @@ -2006,7 +2006,7 @@ If the name is empty, returns the id attribute instead. #### frame.select(selector, value, options) - `selector` <[string]> A selector to query frame for. -- `value` <[string]|[ElementHandle]|[Array]<[string]>|[Object]|[Array]<[ElementHandle]>|[Array]<[Object]>> Options to select. If the `` has the `multiple` attribute, all matching options are selected, otherwise only the first option matching one of the passed options is selected. String values are equivalent to `{value:'string'}`. Option is considered matching if all specified properties match. - `value` <[string]> Matches by `option.value`. - `label` <[string]> Matches by `option.label`. - `index` <[number]> Matches by the index. diff --git a/src/dom.ts b/src/dom.ts index 83673a8313..9f27997dd5 100644 --- a/src/dom.ts +++ b/src/dom.ts @@ -144,9 +144,9 @@ export class ElementHandle extends js.JSHandle { return this; } - _evaluateInUtility: types.EvaluateOn = async (pageFunction, ...args) => { + _evaluateInUtility: types.EvaluateWithInjected = async (pageFunction, ...args) => { const utility = await this._context.frame._utilityContext(); - return utility.evaluate(pageFunction as any, this, ...args); + return utility.evaluate(pageFunction as any, await utility._injected(), this, ...args); } async ownerFrame(): Promise { @@ -163,7 +163,7 @@ export class ElementHandle extends js.JSHandle { } async contentFrame(): Promise { - const isFrameElement = await this._evaluateInUtility(node => node && (node.nodeName === 'IFRAME' || node.nodeName === 'FRAME')); + const isFrameElement = await this._evaluateInUtility((injected, node) => node && (node.nodeName === 'IFRAME' || node.nodeName === 'FRAME')); if (!isFrameElement) return null; return this._page._delegate.getContentFrame(this); @@ -219,12 +219,7 @@ export class ElementHandle extends js.JSHandle { private async _offsetPoint(offset: types.Point): Promise { const [box, border] = await Promise.all([ this.boundingBox(), - this._evaluateInUtility((node: Node) => { - if (node.nodeType !== Node.ELEMENT_NODE || !node.ownerDocument || !node.ownerDocument.defaultView) - return { x: 0, y: 0 }; - const style = node.ownerDocument.defaultView.getComputedStyle(node as Element); - return { x: parseInt(style.borderLeftWidth || '', 10), y: parseInt(style.borderTopWidth || '', 10) }; - }).catch(debugError), + this._evaluateInUtility((injected, node) => injected.getElementBorderWidth(node)).catch(debugError), ]); const point = { x: offset.x, y: offset.y }; if (box) { @@ -233,8 +228,8 @@ export class ElementHandle extends js.JSHandle { } if (border) { // Make point relative to the padding box to align with offsetX/offsetY. - point.x += border.x; - point.y += border.y; + point.x += border.left; + point.y += border.top; } return point; } @@ -286,92 +281,12 @@ export class ElementHandle extends js.JSHandle { if (option.index !== undefined) assert(helper.isNumber(option.index), 'Indices must be numbers. Found index "' + option.index + '" of type "' + (typeof option.index) + '"'); } - return this._evaluateInUtility((node: Node, ...optionsToSelect: (Node | types.SelectOption)[]) => { - if (node.nodeName.toLowerCase() !== 'select') - throw new Error('Element is not a ,