/*! For license information please see 4807700c.a477dca2.js.LICENSE.txt */ "use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[72717],{63e3:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>h,contentTitle:()=>d,default:()=>o,frontMatter:()=>l,metadata:()=>i,toc:()=>a});var r=n(85893),s=n(11151);const l={sidebar_label:"ElementHandle"},d="ElementHandle class",i={id:"api/puppeteer.elementhandle",title:"ElementHandle class",description:"ElementHandle represents an in-page DOM element.",source:"@site/../docs/api/puppeteer.elementhandle.md",sourceDirName:"api",slug:"/api/puppeteer.elementhandle",permalink:"/next/api/puppeteer.elementhandle",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{sidebar_label:"ElementHandle"},sidebar:"api",previous:{title:"JSHandle.toString",permalink:"/next/api/puppeteer.jshandle.tostring"},next:{title:"ElementHandle.$",permalink:"/next/api/puppeteer.elementhandle._"}},h={},a=[{value:"Signature:",id:"signature",level:4},{value:"Remarks",id:"remarks",level:2},{value:"Properties",id:"properties",level:2},{value:"Methods",id:"methods",level:2}];function c(e){const t={a:"a",code:"code",h1:"h1",h2:"h2",h4:"h4",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"elementhandle-class",children:"ElementHandle class"}),"\n",(0,r.jsx)(t.p,{children:"ElementHandle represents an in-page DOM element."}),"\n",(0,r.jsx)(t.h4,{id:"signature",children:"Signature:"}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-typescript",children:"export declare abstract class ElementHandle extends JSHandle\n"})}),"\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.strong,{children:"Extends:"})," ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.jshandle",children:"JSHandle"}),""]}),"\n",(0,r.jsx)(t.h2,{id:"remarks",children:"Remarks"}),"\n",(0,r.jsxs)(t.p,{children:["ElementHandles can be created with the ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.page._",children:"Page.$()"})," method."]}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n\n(async () => {\n const browser = await puppeteer.launch();\n const page = await browser.newPage();\n await page.goto('https://example.com');\n const hrefElement = await page.$('a');\n await hrefElement.click();\n // ...\n})();\n"})}),"\n",(0,r.jsxs)(t.p,{children:["ElementHandle prevents the DOM element from being garbage-collected unless the handle is ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.jshandle.dispose",children:"disposed"}),". ElementHandles are auto-disposed when their origin frame gets navigated."]}),"\n",(0,r.jsxs)(t.p,{children:["ElementHandle instances can be used as arguments in ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.page._eval",children:"Page.$eval()"})," and ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.page.evaluate",children:"Page.evaluate()"})," methods."]}),"\n",(0,r.jsxs)(t.p,{children:["If you're using TypeScript, ElementHandle takes a generic argument that denotes the type of element the handle is holding within. For example, if you have a handle to a ",(0,r.jsx)(t.code,{children:""})," element matching ",(0,r.jsx)("code",{children:"selector"}),", the method throws an error."]})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.tap",children:"tap(this)"})}),(0,r.jsx)(t.td,{}),(0,r.jsxs)(t.td,{children:["This method scrolls element into view if needed, and then uses ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.touchscreen.tap",children:"Touchscreen.tap()"})," to tap in the center of the element. If the element is detached from DOM, the method throws an error."]})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.toelement",children:"toElement(tagName)"})}),(0,r.jsx)(t.td,{}),(0,r.jsx)(t.td,{children:"Converts the current handle to the given element type."})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.touchend",children:"touchEnd(this)"})}),(0,r.jsx)(t.td,{}),(0,r.jsx)(t.td,{})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.touchmove",children:"touchMove(this)"})}),(0,r.jsx)(t.td,{}),(0,r.jsx)(t.td,{})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.touchstart",children:"touchStart(this)"})}),(0,r.jsx)(t.td,{}),(0,r.jsx)(t.td,{})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.type",children:"type(text, options)"})}),(0,r.jsx)(t.td,{}),(0,r.jsxs)(t.td,{children:[(0,r.jsxs)("p",{children:["Focuses the element, and then sends a ",(0,r.jsx)("code",{children:"keydown"}),", ",(0,r.jsx)("code",{children:"keypress"}),"/",(0,r.jsx)("code",{children:"input"}),", and ",(0,r.jsx)("code",{children:"keyup"})," event for each character in the text."]}),(0,r.jsxs)("p",{children:["To press a special key, like ",(0,r.jsx)("code",{children:"Control"})," or ",(0,r.jsx)("code",{children:"ArrowDown"}),", use ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.press",children:"ElementHandle.press()"}),"."]})]})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.uploadfile",children:"uploadFile(this, paths)"})}),(0,r.jsx)(t.td,{}),(0,r.jsxs)(t.td,{children:["Sets the value of an ",(0,r.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input",children:"input element"})," to the given file paths."]})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.waitforselector",children:"waitForSelector(selector, options)"})}),(0,r.jsx)(t.td,{}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)("p",{children:"Wait for an element matching the given selector to appear in the current element."}),(0,r.jsxs)("p",{children:["Unlike ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.frame.waitforselector",children:"Frame.waitForSelector()"}),", this method does not work across navigations or if the element is detached from DOM."]})]})]})]})]})]})}function o(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},75251:(e,t,n)=>{var r=n(67294),s=Symbol.for("react.element"),l=Symbol.for("react.fragment"),d=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,h={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,n){var r,l={},a=null,c=null;for(r in void 0!==n&&(a=""+n),void 0!==t.key&&(a=""+t.key),void 0!==t.ref&&(c=t.ref),t)d.call(t,r)&&!h.hasOwnProperty(r)&&(l[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===l[r]&&(l[r]=t[r]);return{$$typeof:s,type:e,key:a,ref:c,props:l,_owner:i.current}}t.Fragment=l,t.jsx=a,t.jsxs=a},85893:(e,t,n)=>{e.exports=n(75251)},11151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>d});var r=n(67294);const s={},l=r.createContext(s);function d(e){const t=r.useContext(l);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:d(e.components),r.createElement(l.Provider,{value:t},e.children)}}}]);