puppeteer/assets/js/c46890a4.6a4b0735.js
release-please[bot] cc95c085a2 deploy: 1014abc087
2023-11-29 13:34:30 +00:00

2 lines
7.6 KiB
JavaScript

/*! For license information please see c46890a4.6a4b0735.js.LICENSE.txt */
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[15216],{65348:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>s,default:()=>c,frontMatter:()=>l,metadata:()=>o,toc:()=>d});var r=n(85893),i=n(11151);const l={sidebar_label:"ElementHandle.waitForXPath"},s="ElementHandle.waitForXPath() method",o={id:"api/puppeteer.elementhandle.waitforxpath",title:"ElementHandle.waitForXPath() method",description:"Warning: This API is now obsolete.",source:"@site/../docs/api/puppeteer.elementhandle.waitforxpath.md",sourceDirName:"api",slug:"/api/puppeteer.elementhandle.waitforxpath",permalink:"/next/api/puppeteer.elementhandle.waitforxpath",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{sidebar_label:"ElementHandle.waitForXPath"},sidebar:"api",previous:{title:"ElementHandle.waitForSelector",permalink:"/next/api/puppeteer.elementhandle.waitforselector"},next:{title:"HTTPRequest",permalink:"/next/api/puppeteer.httprequest"}},a={},d=[{value:"Signature:",id:"signature",level:4},{value:"Parameters",id:"parameters",level:2},{value:"Remarks",id:"remarks",level:2},{value:"Example",id:"example",level:2}];function h(e){const t={a:"a",blockquote:"blockquote",code:"code",em:"em",h1:"h1",h2:"h2",h4:"h4",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"elementhandlewaitforxpath-method",children:"ElementHandle.waitForXPath() method"}),"\n",(0,r.jsxs)(t.blockquote,{children:["\n",(0,r.jsx)(t.p,{children:"Warning: This API is now obsolete."}),"\n",(0,r.jsxs)(t.p,{children:["Use ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.elementhandle.waitforselector",children:"ElementHandle.waitForSelector()"})," with the ",(0,r.jsx)(t.code,{children:"xpath"})," prefix."]}),"\n",(0,r.jsxs)(t.p,{children:["Example: ",(0,r.jsx)(t.code,{children:"await elementHandle.waitForSelector('xpath/' + xpathExpression)"})]}),"\n",(0,r.jsx)(t.p,{children:"The method evaluates the XPath expression relative to the elementHandle."}),"\n",(0,r.jsxs)(t.p,{children:["Wait for the ",(0,r.jsx)(t.code,{children:"xpath"})," within the element. If at the moment of calling the method the ",(0,r.jsx)(t.code,{children:"xpath"})," already exists, the method will return immediately. If the ",(0,r.jsx)(t.code,{children:"xpath"})," doesn't appear after the ",(0,r.jsx)(t.code,{children:"timeout"})," milliseconds of waiting, the function will throw."]}),"\n",(0,r.jsxs)(t.p,{children:["If ",(0,r.jsx)(t.code,{children:"xpath"})," starts with ",(0,r.jsx)(t.code,{children:"//"})," instead of ",(0,r.jsx)(t.code,{children:".//"}),", the dot will be appended automatically."]}),"\n"]}),"\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 waitForXPath(\n xpath: string,\n options?: {\n visible?: boolean;\n hidden?: boolean;\n timeout?: number;\n }\n ): Promise<ElementHandle<Node> | 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:"xpath"}),(0,r.jsx)(t.td,{children:"string"}),(0,r.jsxs)(t.td,{children:["A ",(0,r.jsx)(t.a,{href:"https://developer.mozilla.org/en-US/docs/Web/XPath",children:"xpath"})," of an element to wait for"]})]}),(0,r.jsxs)(t.tr,{children:[(0,r.jsx)(t.td,{children:"options"}),(0,r.jsx)(t.td,{children:"{ visible?: boolean; hidden?: boolean; timeout?: number; }"}),(0,r.jsxs)(t.td,{children:[(0,r.jsx)(t.em,{children:"(Optional)"})," Optional waiting parameters"]})]})]})]}),"\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"}),"<Node> | null>"]}),"\n",(0,r.jsxs)(t.p,{children:["Promise which resolves when element specified by xpath string is added to DOM. Resolves to ",(0,r.jsx)(t.code,{children:"null"})," if waiting for ",(0,r.jsx)(t.code,{children:"hidden: true"})," and xpath is not found in DOM, otherwise resolves to ",(0,r.jsx)(t.code,{children:"ElementHandle"}),"."]}),"\n",(0,r.jsx)(t.h2,{id:"remarks",children:"Remarks"}),"\n",(0,r.jsxs)(t.p,{children:["The optional Argument ",(0,r.jsx)(t.code,{children:"options"})," have properties:"]}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:["\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"visible"}),": A boolean to wait for element to be present in DOM and to be visible, i.e. to not have ",(0,r.jsx)(t.code,{children:"display: none"})," or ",(0,r.jsx)(t.code,{children:"visibility: hidden"})," CSS properties. Defaults to ",(0,r.jsx)(t.code,{children:"false"}),"."]}),"\n"]}),"\n",(0,r.jsxs)(t.li,{children:["\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"hidden"}),": A boolean wait for element to not be found in the DOM or to be hidden, i.e. have ",(0,r.jsx)(t.code,{children:"display: none"})," or ",(0,r.jsx)(t.code,{children:"visibility: hidden"})," CSS properties. Defaults to ",(0,r.jsx)(t.code,{children:"false"}),"."]}),"\n"]}),"\n",(0,r.jsxs)(t.li,{children:["\n",(0,r.jsxs)(t.p,{children:[(0,r.jsx)(t.code,{children:"timeout"}),": A number which is maximum time to wait for in milliseconds. Defaults to ",(0,r.jsx)(t.code,{children:"30000"})," (30 seconds). Pass ",(0,r.jsx)(t.code,{children:"0"})," to disable timeout. The default value can be changed by using the ",(0,r.jsx)(t.a,{href:"/next/api/puppeteer.page.setdefaulttimeout",children:"Page.setDefaultTimeout()"})," method."]}),"\n"]}),"\n"]}),"\n",(0,r.jsx)(t.h2,{id:"example",children:"Example"}),"\n",(0,r.jsx)(t.p,{children:"This method works across navigation."}),"\n",(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n(async () => {\n const browser = await puppeteer.launch();\n const page = await browser.newPage();\n let currentURL;\n page\n .waitForXPath('//img')\n .then(() => console.log('First URL with image: ' + currentURL));\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 c(e={}){const{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},75251:(e,t,n)=>{var r=n(67294),i=Symbol.for("react.element"),l=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,o=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function d(e,t,n){var r,l={},d=null,h=null;for(r in void 0!==n&&(d=""+n),void 0!==t.key&&(d=""+t.key),void 0!==t.ref&&(h=t.ref),t)s.call(t,r)&&!a.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:i,type:e,key:d,ref:h,props:l,_owner:o.current}}t.Fragment=l,t.jsx=d,t.jsxs=d},85893:(e,t,n)=>{e.exports=n(75251)},11151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>s});var r=n(67294);const i={},l=r.createContext(i);function s(e){const t=r.useContext(l);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),r.createElement(l.Provider,{value:t},e.children)}}}]);