mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
2 lines
5.3 KiB
JavaScript
2 lines
5.3 KiB
JavaScript
/*! For license information please see 2462b75c.c2b2dc0d.js.LICENSE.txt */
|
|
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[3913],{87524:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>a,default:()=>d,frontMatter:()=>l,metadata:()=>i,toc:()=>c});var r=n(85893),o=n(11151);const l={sidebar_label:"ElementHandle.waitForSelector"},a="ElementHandle.waitForSelector() method",i={id:"api/puppeteer.elementhandle.waitforselector",title:"ElementHandle.waitForSelector() method",description:"Wait for an element matching the given selector to appear in the current element.",source:"@site/../docs/api/puppeteer.elementhandle.waitforselector.md",sourceDirName:"api",slug:"/api/puppeteer.elementhandle.waitforselector",permalink:"/next/api/puppeteer.elementhandle.waitforselector",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{sidebar_label:"ElementHandle.waitForSelector"},sidebar:"api",previous:{title:"ElementHandle.uploadFile",permalink:"/next/api/puppeteer.elementhandle.uploadfile"},next:{title:"HTTPRequest",permalink:"/next/api/puppeteer.httprequest"}},s={},c=[{value:"Signature:",id:"signature",level:4},{value:"Parameters",id:"parameters",level:2},{value:"Exceptions",id:"exceptions",level:2},{value:"Example",id:"example",level:2}];function p(e){const t={a:"a",code:"code",em:"em",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,o.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"elementhandlewaitforselector-method",children:"ElementHandle.waitForSelector() method"}),"\n",(0,r.jsx)(t.p,{children:"Wait for an element matching the given selector to appear in the current element."}),"\n",(0,r.jsxs)(t.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."]}),"\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:"class ElementHandle {\n waitForSelector<Selector extends string>(\n selector: Selector,\n options?: WaitForSelectorOptions\n ): Promise<ElementHandle<NodeFor<Selector>> | null>;\n}\n"})}),"\n",(0,r.jsx)(t.h2,{id:"parameters",children:"Parameters"}),"\n",(0,r.jsxs)(t.table,{children:[(0,r.jsx)(t.thead,{children:(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.th,{children:"Parameter"}),(0,r.jsx)(t.th,{children:"Type"}),(0,r.jsx)(t.th,{children:"Description"})]})}),(0,r.jsxs)(t.tbody,{children:[(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"selector"}),(0,r.jsx)(t.td,{children:"Selector"}),(0,r.jsx)(t.td,{children:"The selector to query and wait for."})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"options"}),(0,r.jsx)(t.td,{children:(0,r.jsx)(t.a,{href:"/next/api/puppeteer.waitforselectoroptions",children:"WaitForSelectorOptions"})}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.em,{children:"(Optional)"})," Options for customizing waiting behavior."]})]})]})]}),"\n",(0,r.jsx)(t.p,{children:(0,r.jsx)(t.strong,{children:"Returns:"})}),"\n",(0,r.jsxs)(t.p,{children:["Promise<",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle",children:"ElementHandle"}),"<",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.nodefor",children:"NodeFor"}),"<Selector>> | null>"]}),"\n",(0,r.jsx)(t.p,{children:"An element matching the given selector."}),"\n",(0,r.jsx)(t.h2,{id:"exceptions",children:"Exceptions"}),"\n",(0,r.jsx)(t.p,{children:"Throws if an element matching the given selector doesn't appear."}),"\n",(0,r.jsx)(t.h2,{id:"example",children:"Example"}),"\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 let currentURL;\n page\n .mainFrame()\n .waitForSelector('img')\n .then(() => console.log('First URL with image: ' + currentURL));\n\n for (currentURL of [\n 'https://example.com',\n 'https://google.com',\n 'https://bbc.com',\n ]) {\n await page.goto(currentURL);\n }\n await browser.close();\n})();\n"})})]})}function d(e={}){const{wrapper:t}={...(0,o.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},75251:(e,t,n)=>{var r=n(67294),o=Symbol.for("react.element"),l=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,i=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,n){var r,l={},c=null,p=null;for(r in void 0!==n&&(c=""+n),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(p=t.ref),t)a.call(t,r)&&!s.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:o,type:e,key:c,ref:p,props:l,_owner:i.current}}t.Fragment=l,t.jsx=c,t.jsxs=c},85893:(e,t,n)=>{e.exports=n(75251)},11151:(e,t,n)=>{n.d(t,{Z:()=>i,a:()=>a});var r=n(67294);const o={},l=r.createContext(o);function a(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(o):e.components||o:a(e.components),r.createElement(l.Provider,{value:t},e.children)}}}]); |