diff --git a/docs/api.md b/docs/api.md index c57280491fa..7b84407e59b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -106,6 +106,7 @@ + [frame.waitForFunction(pageFunction[, options, ...args])](#framewaitforfunctionpagefunction-options-args) + [frame.waitForSelector(selector[, options])](#framewaitforselectorselector-options) * [class: ElementHandle](#class-elementhandle) + + [elementHandle.attribute(key)](#elementhandleattributekey) + [elementHandle.click([options])](#elementhandleclickoptions) + [elementHandle.dispose()](#elementhandledispose) + [elementHandle.evaluate(pageFunction, ...args)](#elementhandleevaluatepagefunction-args) @@ -1189,6 +1190,21 @@ puppeteer.launch().then(async browser => { ElementHandle prevents DOM element from garbage collection unless the handle is [disposed](#elementhandledispose). ElementHandles are auto-disposed when their origin frame gets navigated. +#### elementHandle.attribute(key) +- `key` the name the attribute of this Element. +- returns: <[Promise]> + +```js +const puppeteer = require('puppeteer'); + +puppeteer.launch().then(async browser => { + const page = await browser.newPage(); + await page.goto('https://google.com'); + const inputElement = await page.$('input'); + const inputType = await inputElement.attribute('type'); +}); +``` + #### elementHandle.click([options]) - `options` <[Object]> - `button` <[string]> `left`, `right`, or `middle`, defaults to `left`. diff --git a/lib/ElementHandle.js b/lib/ElementHandle.js index 1e8578b2225..8a454e1b1f0 100644 --- a/lib/ElementHandle.js +++ b/lib/ElementHandle.js @@ -103,6 +103,15 @@ class ElementHandle { const objectId = this._remoteObject.objectId; return this._client.send('DOM.setFileInputFiles', { objectId, files }); } + + /** + * @param {! element.getAttribute(key), key); + } + } module.exports = ElementHandle; diff --git a/test/test.js b/test/test.js index 6881700b567..868175c5d5a 100644 --- a/test/test.js +++ b/test/test.js @@ -1180,6 +1180,12 @@ describe('Page', function() { } expect(error.message).toContain('ElementHandle is disposed'); })); + it('should return attribute', SX(async function() { + await page.setContent('
43543
'); + const element = await page.$('section'); + expect(element).toBeTruthy(); + expect(await element.attribute('id')).toBe('testAttribute'); + })); }); describe('ElementHandle.click', function() {