diff --git a/docs/src/api/class-elementhandle.md b/docs/src/api/class-elementhandle.md index d73daaeb99..1db0def888 100644 --- a/docs/src/api/class-elementhandle.md +++ b/docs/src/api/class-elementhandle.md @@ -499,6 +499,13 @@ Returns the `element.innerHTML`. Returns the `element.innerText`. +## async method: ElementHandle.inputValue +- returns: <[string]> + +Returns `input.value` for `` or ` diff --git a/tests/page/elementhandle-convenience.spec.ts b/tests/page/elementhandle-convenience.spec.ts index db3c5d382f..79ba9ce5a4 100644 --- a/tests/page/elementhandle-convenience.spec.ts +++ b/tests/page/elementhandle-convenience.spec.ts @@ -39,6 +39,22 @@ it('getAttribute should work', async ({ page, server }) => { expect(await page.getAttribute('#outer', 'foo')).toBe(null); }); +it('inputValue should work', async ({ page, server }) => { + await page.goto(`${server.PREFIX}/dom.html`); + + await page.fill('#textarea', 'text value'); + expect(await page.inputValue('#textarea')).toBe('text value'); + + await page.fill('#input', 'input value'); + expect(await page.inputValue('#input')).toBe('input value'); + const handle = await page.$('#input'); + expect(await handle.inputValue()).toBe('input value'); + + expect(await page.inputValue('#inner').catch(e => e.message)).toContain('Node is not an HTMLInputElement or HTMLTextAreaElement'); + const handle2 = await page.$('#inner'); + expect(await handle2.inputValue().catch(e => e.message)).toContain('Node is not an HTMLInputElement or HTMLTextAreaElement'); +}); + it('innerHTML should work', async ({ page, server }) => { await page.goto(`${server.PREFIX}/dom.html`); const handle = await page.$('#outer'); diff --git a/types/types.d.ts b/types/types.d.ts index 99ca05c285..b060b7af5c 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -2024,6 +2024,21 @@ export interface Page { timeout?: number; }): Promise; + /** + * Returns `input.value` for the selected `` or `