diff --git a/src/client/locator.ts b/src/client/locator.ts index 3ec73d4b81..07af9237b3 100644 --- a/src/client/locator.ts +++ b/src/client/locator.ts @@ -34,10 +34,10 @@ export class Locator implements api.Locator { private async _withElement(task: (handle: ElementHandle, options?: O) => Promise, options?: O): Promise { if (!options) - options = {} as any; + options = {} as O; const timeout = this._frame.page()._timeoutSettings.timeout(options!); const deadline = timeout ? monotonicTime() + timeout : 0; - const handle = await this.elementHandle(options); + const handle = await this.elementHandle({ timeout }); if (!handle) throw new Error(`Could not resolve ${this._selector} to DOM Element`); try { @@ -68,15 +68,15 @@ export class Locator implements api.Locator { } async evaluate(pageFunction: structs.PageFunctionOn, arg?: Arg, options?: TimeoutOptions): Promise { - return this._withElement(h => h.evaluate(pageFunction as any, arg), { strict: true, ...options }); + return this._withElement(h => h.evaluate(pageFunction, arg), { strict: true, ...options }); } - async evaluateAll(pageFunction: structs.PageFunctionOn<(SVGElement | HTMLElement)[], Arg, R>, arg?: Arg): Promise { - return this._frame.$$eval(this._selector, pageFunction as any, arg); + async evaluateAll(pageFunction: structs.PageFunctionOn, arg?: Arg): Promise { + return this._frame.$$eval(this._selector, pageFunction, arg); } - async evaluateHandle(pageFunction: structs.PageFunction, arg?: Arg, options?: TimeoutOptions): Promise> { - return this._withElement(h => h.evaluateHandle(pageFunction as any, arg), { strict: true, ...options }); + async evaluateHandle(pageFunction: structs.PageFunctionOn, arg?: Arg, options?: TimeoutOptions): Promise> { + return this._withElement(h => h.evaluateHandle(pageFunction, arg), { strict: true, ...options }); } async fill(value: string, options: channels.ElementHandleFillOptions = {}): Promise { @@ -88,8 +88,7 @@ export class Locator implements api.Locator { } async elementHandle(options?: TimeoutOptions): Promise> { - const result = await this._frame.waitForSelector(this._selector, { strict: true, state: 'attached', ...options }); - return result!; + return await this._frame.waitForSelector(this._selector, { strict: true, state: 'attached', ...options })!; } async elementHandles(): Promise[]> { diff --git a/tests/page/locator-convenience.spec.ts b/tests/page/locator-convenience.spec.ts index a8cd9ed5b0..e9f146268c 100644 --- a/tests/page/locator-convenience.spec.ts +++ b/tests/page/locator-convenience.spec.ts @@ -200,12 +200,12 @@ it('isChecked should work', async ({page}) => { expect(error.message).toContain('Not a checkbox or radio button'); }); -it('addTextContents should work', async ({page}) => { +it('allTextContents should work', async ({page}) => { await page.setContent(`
A
B
C
`); expect(await page.locator('div').allTextContents()).toEqual(['A', 'B', 'C']); }); -it('addInnerTexts should work', async ({page}) => { +it('allInnerTexts should work', async ({page}) => { await page.setContent(`
A
B
C
`); expect(await page.locator('div').allInnerTexts()).toEqual(['A', 'B', 'C']); });