From 5cf9b4de8d50bd056db82bcaa23279b72c9313c5 Mon Sep 17 00:00:00 2001
From: jrandolf <101637635+jrandolf@users.noreply.github.com>
Date: Thu, 4 Aug 2022 15:45:21 +0200
Subject: [PATCH] feat: use an `xpath` query handler (#8730)
---
docs/api/index.md | 114 ++++++------
docs/api/puppeteer.customqueryhandler.md | 10 +-
.../puppeteer.customqueryhandler.queryall.md | 2 +-
.../puppeteer.customqueryhandler.queryone.md | 2 +-
docs/api/puppeteer.elementhandle._x.md | 6 +-
docs/api/puppeteer.elementhandle.md | 80 +++------
.../puppeteer.elementhandle.waitforxpath.md | 54 +++---
docs/api/puppeteer.frame.waitforxpath.md | 14 +-
src/common/AriaQueryHandler.ts | 2 +-
src/common/DOMWorld.ts | 46 -----
src/common/ElementHandle.ts | 54 ++----
src/common/FrameManager.ts | 13 +-
src/common/QueryHandler.ts | 166 ++++++++++++------
test/src/elementhandle.spec.ts | 10 +-
test/src/queryhandler.spec.ts | 160 +++++++++++++++++
test/src/queryselector.spec.ts | 74 +-------
test/src/waittask.spec.ts | 2 +-
17 files changed, 426 insertions(+), 383 deletions(-)
create mode 100644 test/src/queryhandler.spec.ts
diff --git a/docs/api/index.md b/docs/api/index.md
index 03f904ac..af448142 100644
--- a/docs/api/index.md
+++ b/docs/api/index.md
@@ -61,63 +61,63 @@ sidebar_label: API
## Interfaces
-| Interface | Description |
-| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| [BoundingBox](./puppeteer.boundingbox.md) | |
-| [BoxModel](./puppeteer.boxmodel.md) | |
-| [BrowserConnectOptions](./puppeteer.browserconnectoptions.md) | Generic browser options that can be passed when launching any browser or when connecting to an existing browser instance. |
-| [BrowserContextOptions](./puppeteer.browsercontextoptions.md) | BrowserContext options. |
-| [BrowserFetcherOptions](./puppeteer.browserfetcheroptions.md) | |
-| [BrowserFetcherRevisionInfo](./puppeteer.browserfetcherrevisioninfo.md) | |
-| [BrowserLaunchArgumentOptions](./puppeteer.browserlaunchargumentoptions.md) | Launcher options that only apply to Chrome. |
-| [CDPSessionOnMessageObject](./puppeteer.cdpsessiononmessageobject.md) | |
-| [ClickOptions](./puppeteer.clickoptions.md) | |
-| [CommonEventEmitter](./puppeteer.commoneventemitter.md) | |
-| [ConnectionCallback](./puppeteer.connectioncallback.md) | |
-| [ConnectionTransport](./puppeteer.connectiontransport.md) | |
-| [ConnectOptions](./puppeteer.connectoptions.md) | |
-| [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) | |
-| [ContinueRequestOverrides](./puppeteer.continuerequestoverrides.md) | |
-| [CoverageEntry](./puppeteer.coverageentry.md) | The CoverageEntry class represents one entry of the coverage report. |
-| [Credentials](./puppeteer.credentials.md) | |
-| [CSSCoverageOptions](./puppeteer.csscoverageoptions.md) | Set of configurable options for CSS coverage. |
-| [CustomQueryHandler](./puppeteer.customqueryhandler.md) | Contains two functions queryOne
and queryAll
that can be [registered](./puppeteer.registercustomqueryhandler.md) as alternative querying strategies. The functions queryOne
and queryAll
are executed in the page context. queryOne
should take an Element
and a selector string as argument and return a single Element
or null
if no element is found. queryAll
takes the same arguments but should instead return a NodeListOf<Element>
or Array<Element>
with all the elements that match the given query selector. |
-| [Device](./puppeteer.device.md) | |
-| [FrameAddScriptTagOptions](./puppeteer.frameaddscripttagoptions.md) | |
-| [FrameAddStyleTagOptions](./puppeteer.frameaddstyletagoptions.md) | |
-| [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | |
-| [GeolocationOptions](./puppeteer.geolocationoptions.md) | |
-| [InterceptResolutionState](./puppeteer.interceptresolutionstate.md) | |
-| [InternalNetworkConditions](./puppeteer.internalnetworkconditions.md) | |
-| [JSCoverageEntry](./puppeteer.jscoverageentry.md) | The CoverageEntry class for JavaScript |
-| [JSCoverageOptions](./puppeteer.jscoverageoptions.md) | Set of configurable options for JS coverage. |
-| [LaunchOptions](./puppeteer.launchoptions.md) | Generic launch options that can be passed when launching any browser. |
-| [MediaFeature](./puppeteer.mediafeature.md) | |
-| [Metrics](./puppeteer.metrics.md) | |
-| [MouseOptions](./puppeteer.mouseoptions.md) | |
-| [MouseWheelOptions](./puppeteer.mousewheeloptions.md) | |
-| [NetworkConditions](./puppeteer.networkconditions.md) | |
-| [Offset](./puppeteer.offset.md) | |
-| [PageEventObject](./puppeteer.pageeventobject.md) |
Denotes the objects received by callback functions for page events.
See [PageEmittedEvents](./puppeteer.pageemittedevents.md) for more detail on the events and when they are emitted.
| -| [PDFMargin](./puppeteer.pdfmargin.md) | | -| [PDFOptions](./puppeteer.pdfoptions.md) | Valid options to configure PDF generation via [Page.pdf()](./puppeteer.page.pdf.md). | -| [Point](./puppeteer.point.md) | | -| [PressOptions](./puppeteer.pressoptions.md) | | -| [ProductLauncher](./puppeteer.productlauncher.md) | Describes a launcher - a class that is able to create and launch a browser instance. | -| [PuppeteerErrors](./puppeteer.puppeteererrors.md) | | -| [PuppeteerLaunchOptions](./puppeteer.puppeteerlaunchoptions.md) | | -| [RemoteAddress](./puppeteer.remoteaddress.md) | | -| [ResponseForRequest](./puppeteer.responseforrequest.md) | Required response data to fulfill a request with. | -| [ScreenshotClip](./puppeteer.screenshotclip.md) | | -| [ScreenshotOptions](./puppeteer.screenshotoptions.md) | | -| [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. | -| [SnapshotOptions](./puppeteer.snapshotoptions.md) | | -| [TracingOptions](./puppeteer.tracingoptions.md) | | -| [Viewport](./puppeteer.viewport.md) | Sets the viewport of the page. | -| [WaitForOptions](./puppeteer.waitforoptions.md) | | -| [WaitForSelectorOptions](./puppeteer.waitforselectoroptions.md) | | -| [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md) | | -| [WaitTimeoutOptions](./puppeteer.waittimeoutoptions.md) | | +| Interface | Description | +| --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [BoundingBox](./puppeteer.boundingbox.md) | | +| [BoxModel](./puppeteer.boxmodel.md) | | +| [BrowserConnectOptions](./puppeteer.browserconnectoptions.md) | Generic browser options that can be passed when launching any browser or when connecting to an existing browser instance. | +| [BrowserContextOptions](./puppeteer.browsercontextoptions.md) | BrowserContext options. | +| [BrowserFetcherOptions](./puppeteer.browserfetcheroptions.md) | | +| [BrowserFetcherRevisionInfo](./puppeteer.browserfetcherrevisioninfo.md) | | +| [BrowserLaunchArgumentOptions](./puppeteer.browserlaunchargumentoptions.md) | Launcher options that only apply to Chrome. | +| [CDPSessionOnMessageObject](./puppeteer.cdpsessiononmessageobject.md) | | +| [ClickOptions](./puppeteer.clickoptions.md) | | +| [CommonEventEmitter](./puppeteer.commoneventemitter.md) | | +| [ConnectionCallback](./puppeteer.connectioncallback.md) | | +| [ConnectionTransport](./puppeteer.connectiontransport.md) | | +| [ConnectOptions](./puppeteer.connectoptions.md) | | +| [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) | | +| [ContinueRequestOverrides](./puppeteer.continuerequestoverrides.md) | | +| [CoverageEntry](./puppeteer.coverageentry.md) | The CoverageEntry class represents one entry of the coverage report. | +| [Credentials](./puppeteer.credentials.md) | | +| [CSSCoverageOptions](./puppeteer.csscoverageoptions.md) | Set of configurable options for CSS coverage. | +| [CustomQueryHandler](./puppeteer.customqueryhandler.md) | | +| [Device](./puppeteer.device.md) | | +| [FrameAddScriptTagOptions](./puppeteer.frameaddscripttagoptions.md) | | +| [FrameAddStyleTagOptions](./puppeteer.frameaddstyletagoptions.md) | | +| [FrameWaitForFunctionOptions](./puppeteer.framewaitforfunctionoptions.md) | | +| [GeolocationOptions](./puppeteer.geolocationoptions.md) | | +| [InterceptResolutionState](./puppeteer.interceptresolutionstate.md) | | +| [InternalNetworkConditions](./puppeteer.internalnetworkconditions.md) | | +| [JSCoverageEntry](./puppeteer.jscoverageentry.md) | The CoverageEntry class for JavaScript | +| [JSCoverageOptions](./puppeteer.jscoverageoptions.md) | Set of configurable options for JS coverage. | +| [LaunchOptions](./puppeteer.launchoptions.md) | Generic launch options that can be passed when launching any browser. | +| [MediaFeature](./puppeteer.mediafeature.md) | | +| [Metrics](./puppeteer.metrics.md) | | +| [MouseOptions](./puppeteer.mouseoptions.md) | | +| [MouseWheelOptions](./puppeteer.mousewheeloptions.md) | | +| [NetworkConditions](./puppeteer.networkconditions.md) | | +| [Offset](./puppeteer.offset.md) | | +| [PageEventObject](./puppeteer.pageeventobject.md) |Denotes the objects received by callback functions for page events.
See [PageEmittedEvents](./puppeteer.pageemittedevents.md) for more detail on the events and when they are emitted.
| +| [PDFMargin](./puppeteer.pdfmargin.md) | | +| [PDFOptions](./puppeteer.pdfoptions.md) | Valid options to configure PDF generation via [Page.pdf()](./puppeteer.page.pdf.md). | +| [Point](./puppeteer.point.md) | | +| [PressOptions](./puppeteer.pressoptions.md) | | +| [ProductLauncher](./puppeteer.productlauncher.md) | Describes a launcher - a class that is able to create and launch a browser instance. | +| [PuppeteerErrors](./puppeteer.puppeteererrors.md) | | +| [PuppeteerLaunchOptions](./puppeteer.puppeteerlaunchoptions.md) | | +| [RemoteAddress](./puppeteer.remoteaddress.md) | | +| [ResponseForRequest](./puppeteer.responseforrequest.md) | Required response data to fulfill a request with. | +| [ScreenshotClip](./puppeteer.screenshotclip.md) | | +| [ScreenshotOptions](./puppeteer.screenshotoptions.md) | | +| [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. | +| [SnapshotOptions](./puppeteer.snapshotoptions.md) | | +| [TracingOptions](./puppeteer.tracingoptions.md) | | +| [Viewport](./puppeteer.viewport.md) | Sets the viewport of the page. | +| [WaitForOptions](./puppeteer.waitforoptions.md) | | +| [WaitForSelectorOptions](./puppeteer.waitforselectoroptions.md) | | +| [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md) | | +| [WaitTimeoutOptions](./puppeteer.waittimeoutoptions.md) | | ## Variables diff --git a/docs/api/puppeteer.customqueryhandler.md b/docs/api/puppeteer.customqueryhandler.md index e2420101..67e1123a 100644 --- a/docs/api/puppeteer.customqueryhandler.md +++ b/docs/api/puppeteer.customqueryhandler.md @@ -4,8 +4,6 @@ sidebar_label: CustomQueryHandler # CustomQueryHandler interface -Contains two functions `queryOne` and `queryAll` that can be [registered](./puppeteer.registercustomqueryhandler.md) as alternative querying strategies. The functions `queryOne` and `queryAll` are executed in the page context. `queryOne` should take an `Element` and a selector string as argument and return a single `Element` or `null` if no element is found. `queryAll` takes the same arguments but should instead return a `NodeListOfelement.querySelector
within the page. |
-| [$$(selector)](./puppeteer.elementhandle.__.md) | | Runs element.querySelectorAll
within the page. |
-| [$$eval(selector, pageFunction, args)](./puppeteer.elementhandle.__eval.md) | | This method runs document.querySelectorAll
within the element and passes it as the first argument to pageFunction
. If there's no element matching selector
, the method throws an error.
If pageFunction
returns a Promise, then frame.$$eval
would wait for the promise to resolve and return its value.
This method runs document.querySelector
within the element and passes it as the first argument to pageFunction
. If there's no element matching selector
, the method throws an error.
If pageFunction
returns a Promise, then frame.$eval
would wait for the promise to resolve and return its value.
null
if the element is not visible. |
-| [boxModel()](./puppeteer.elementhandle.boxmodel.md) | | This method returns boxes of the element, or null
if the element is not visible. |
-| [click(this, options)](./puppeteer.elementhandle.click.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.mouse.md) to click in the center of the element. If the element is detached from DOM, the method throws an error. |
-| [clickablePoint(offset)](./puppeteer.elementhandle.clickablepoint.md) | | Returns the middle point within an element unless a specific offset is provided. |
-| [contentFrame()](./puppeteer.elementhandle.contentframe.md) | | Resolves to the content frame for element handles referencing iframe nodes, or null otherwise |
-| [drag(this, target)](./puppeteer.elementhandle.drag.md) | | This method creates and captures a dragevent from the element. |
-| [dragAndDrop(this, target, options)](./puppeteer.elementhandle.draganddrop.md) | | This method triggers a dragenter, dragover, and drop on the element. |
-| [dragEnter(this, data)](./puppeteer.elementhandle.dragenter.md) | | This method creates a dragenter
event on the element. |
-| [dragOver(this, data)](./puppeteer.elementhandle.dragover.md) | | This method creates a dragover
event on the element. |
-| [drop(this, data)](./puppeteer.elementhandle.drop.md) | | This method triggers a drop on the element. |
-| [focus()](./puppeteer.elementhandle.focus.md) | | Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element. |
-| [hover(this)](./puppeteer.elementhandle.hover.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.mouse.md) to hover over the center of the element. If the element is detached from DOM, the method throws an error. |
-| [isIntersectingViewport(this, options)](./puppeteer.elementhandle.isintersectingviewport.md) | | Resolves to true if the element is visible in the current viewport. |
-| [press(key, options)](./puppeteer.elementhandle.press.md) | | Focuses the element, and then uses [Keyboard.down()](./puppeteer.keyboard.down.md) and [Keyboard.up()](./puppeteer.keyboard.up.md). |
-| [screenshot(this, options)](./puppeteer.elementhandle.screenshot.md) | | This method scrolls element into view if needed, and then uses [Page.screenshot()](./puppeteer.page.screenshot.md) to take a screenshot of the element. If the element is detached from DOM, the method throws an error. |
-| [select(values)](./puppeteer.elementhandle.select.md) | | Triggers a change
and input
event once all the provided options have been selected. If there's no <select>
element matching selector
, the method throws an error. |
-| [tap(this)](./puppeteer.elementhandle.tap.md) | | This method scrolls element into view if needed, and then uses [Touchscreen.tap()](./puppeteer.touchscreen.tap.md) to tap in the center of the element. If the element is detached from DOM, the method throws an error. |
-| [type(text, options)](./puppeteer.elementhandle.type.md) | | Focuses the element, and then sends a keydown
, keypress
/input
, and keyup
event for each character in the text.
To press a special key, like Control
or ArrowDown
, use [ElementHandle.press()](./puppeteer.elementhandle.press.md).
elementHandle
to point to an [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). |
-| [waitForSelector(selector, options)](./puppeteer.elementhandle.waitforselector.md) | | Wait for the selector
to appear within the element. If at the moment of calling the method the selector
already exists, the method will return immediately. If the selector
doesn't appear after the timeout
milliseconds of waiting, the function will throw.
This method does not work across navigations or if the element is detached from DOM.
| -| [waitForXPath(xpath, options)](./puppeteer.elementhandle.waitforxpath.md) | |Wait for the xpath
within the element. If at the moment of calling the method the xpath
already exists, the method will return immediately. If the xpath
doesn't appear after the timeout
milliseconds of waiting, the function will throw.
If xpath
starts with //
instead of .//
, the dot will be appended automatically.
This method works across navigation
| - -```ts -const puppeteer = require('puppeteer'); -(async () => { - const browser = await puppeteer.launch(); - const page = await browser.newPage(); - let currentURL; - page - .waitForXPath('//img') - .then(() => console.log('First URL with image: ' + currentURL)); - for (currentURL of [ - 'https://example.com', - 'https://google.com', - 'https://bbc.com', - ]) { - await page.goto(currentURL); - } - await browser.close(); -})(); -``` - -| +| Method | Modifiers | Description | +| -------------------------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [$(selector)](./puppeteer.elementhandle._.md) | | Runselement.querySelector
within the page. |
+| [$$(selector)](./puppeteer.elementhandle.__.md) | | Runs element.querySelectorAll
within the page. |
+| [$$eval(selector, pageFunction, args)](./puppeteer.elementhandle.__eval.md) | | This method runs document.querySelectorAll
within the element and passes it as the first argument to pageFunction
. If there's no element matching selector
, the method throws an error.
If pageFunction
returns a Promise, then frame.$$eval
would wait for the promise to resolve and return its value.
This method runs document.querySelector
within the element and passes it as the first argument to pageFunction
. If there's no element matching selector
, the method throws an error.
If pageFunction
returns a Promise, then frame.$eval
would wait for the promise to resolve and return its value.
null
if the element is not visible. |
+| [boxModel()](./puppeteer.elementhandle.boxmodel.md) | | This method returns boxes of the element, or null
if the element is not visible. |
+| [click(this, options)](./puppeteer.elementhandle.click.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.mouse.md) to click in the center of the element. If the element is detached from DOM, the method throws an error. |
+| [clickablePoint(offset)](./puppeteer.elementhandle.clickablepoint.md) | | Returns the middle point within an element unless a specific offset is provided. |
+| [contentFrame()](./puppeteer.elementhandle.contentframe.md) | | Resolves to the content frame for element handles referencing iframe nodes, or null otherwise |
+| [drag(this, target)](./puppeteer.elementhandle.drag.md) | | This method creates and captures a dragevent from the element. |
+| [dragAndDrop(this, target, options)](./puppeteer.elementhandle.draganddrop.md) | | This method triggers a dragenter, dragover, and drop on the element. |
+| [dragEnter(this, data)](./puppeteer.elementhandle.dragenter.md) | | This method creates a dragenter
event on the element. |
+| [dragOver(this, data)](./puppeteer.elementhandle.dragover.md) | | This method creates a dragover
event on the element. |
+| [drop(this, data)](./puppeteer.elementhandle.drop.md) | | This method triggers a drop on the element. |
+| [focus()](./puppeteer.elementhandle.focus.md) | | Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element. |
+| [hover(this)](./puppeteer.elementhandle.hover.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.mouse.md) to hover over the center of the element. If the element is detached from DOM, the method throws an error. |
+| [isIntersectingViewport(this, options)](./puppeteer.elementhandle.isintersectingviewport.md) | | Resolves to true if the element is visible in the current viewport. |
+| [press(key, options)](./puppeteer.elementhandle.press.md) | | Focuses the element, and then uses [Keyboard.down()](./puppeteer.keyboard.down.md) and [Keyboard.up()](./puppeteer.keyboard.up.md). |
+| [screenshot(this, options)](./puppeteer.elementhandle.screenshot.md) | | This method scrolls element into view if needed, and then uses [Page.screenshot()](./puppeteer.page.screenshot.md) to take a screenshot of the element. If the element is detached from DOM, the method throws an error. |
+| [select(values)](./puppeteer.elementhandle.select.md) | | Triggers a change
and input
event once all the provided options have been selected. If there's no <select>
element matching selector
, the method throws an error. |
+| [tap(this)](./puppeteer.elementhandle.tap.md) | | This method scrolls element into view if needed, and then uses [Touchscreen.tap()](./puppeteer.touchscreen.tap.md) to tap in the center of the element. If the element is detached from DOM, the method throws an error. |
+| [type(text, options)](./puppeteer.elementhandle.type.md) | | Focuses the element, and then sends a keydown
, keypress
/input
, and keyup
event for each character in the text.
To press a special key, like Control
or ArrowDown
, use [ElementHandle.press()](./puppeteer.elementhandle.press.md).
elementHandle
to point to an [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). |
+| [waitForSelector(selector, options)](./puppeteer.elementhandle.waitforselector.md) | | Wait for the selector
to appear within the element. If at the moment of calling the method the selector
already exists, the method will return immediately. If the selector
doesn't appear after the timeout
milliseconds of waiting, the function will throw.
This method does not work across navigations or if the element is detached from DOM.
| +| [waitForXPath(xpath, options)](./puppeteer.elementhandle.waitforxpath.md) | | | diff --git a/docs/api/puppeteer.elementhandle.waitforxpath.md b/docs/api/puppeteer.elementhandle.waitforxpath.md index 631eefcb..1a626e6c 100644 --- a/docs/api/puppeteer.elementhandle.waitforxpath.md +++ b/docs/api/puppeteer.elementhandle.waitforxpath.md @@ -4,31 +4,35 @@ sidebar_label: ElementHandle.waitForXPath # ElementHandle.waitForXPath() method -Wait for the `xpath` within the element. If at the moment of calling the method the `xpath` already exists, the method will return immediately. If the `xpath` doesn't appear after the `timeout` milliseconds of waiting, the function will throw. - -If `xpath` starts with `//` instead of `.//`, the dot will be appended automatically. - -This method works across navigation - -```ts -const puppeteer = require('puppeteer'); -(async () => { - const browser = await puppeteer.launch(); - const page = await browser.newPage(); - let currentURL; - page - .waitForXPath('//img') - .then(() => console.log('First URL with image: ' + currentURL)); - for (currentURL of [ - 'https://example.com', - 'https://google.com', - 'https://bbc.com', - ]) { - await page.goto(currentURL); - } - await browser.close(); -})(); -``` +> Warning: This API is now obsolete. +> +> Use [ElementHandle.waitForSelector()](./puppeteer.elementhandle.waitforselector.md) with the `xpath` prefix. +> +> Wait for the `xpath` within the element. If at the moment of calling the method the `xpath` already exists, the method will return immediately. If the `xpath` doesn't appear after the `timeout` milliseconds of waiting, the function will throw. +> +> If `xpath` starts with `//` instead of `.//`, the dot will be appended automatically. +> +> This method works across navigation +> +> ```ts +> const puppeteer = require('puppeteer'); +> (async () => { +> const browser = await puppeteer.launch(); +> const page = await browser.newPage(); +> let currentURL; +> page +> .waitForXPath('//img') +> .then(() => console.log('First URL with image: ' + currentURL)); +> for (currentURL of [ +> 'https://example.com', +> 'https://google.com', +> 'https://bbc.com', +> ]) { +> await page.goto(currentURL); +> } +> await browser.close(); +> })(); +> ``` **Signature:** diff --git a/docs/api/puppeteer.frame.waitforxpath.md b/docs/api/puppeteer.frame.waitforxpath.md index b03f1e2c..c791a19c 100644 --- a/docs/api/puppeteer.frame.waitforxpath.md +++ b/docs/api/puppeteer.frame.waitforxpath.md @@ -4,6 +4,14 @@ sidebar_label: Frame.waitForXPath # Frame.waitForXPath() method +> Warning: This API is now obsolete. +> +> Use [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md) with the `xpath` prefix. +> +> Wait for the `xpath` to appear in page. If at the moment of calling the method the `xpath` already exists, the method will return immediately. If the xpath doesn't appear after the `timeout` milliseconds of waiting, the function will throw. +> +> For a code example, see the example for [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md). That function behaves identically other than taking a CSS selector rather than an XPath. + **Signature:** ```typescript @@ -25,9 +33,3 @@ class Frame { **Returns:** Promise<[ElementHandle](./puppeteer.elementhandle.md)<Node> \| null> - -## Remarks - -Wait for the `xpath` to appear in page. If at the moment of calling the method the `xpath` already exists, the method will return immediately. If the xpath doesn't appear after the `timeout` milliseconds of waiting, the function will throw. - -For a code example, see the example for [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md). That function behaves identically other than taking a CSS selector rather than an XPath. diff --git a/src/common/AriaQueryHandler.ts b/src/common/AriaQueryHandler.ts index 466e1589..a2f82ccc 100644 --- a/src/common/AriaQueryHandler.ts +++ b/src/common/AriaQueryHandler.ts @@ -114,7 +114,7 @@ const waitFor = async ( return (await domWorld._waitForSelectorInPage( (_: Element, selector: string) => { return ( - globalThis as any as unknown as { + globalThis as unknown as { ariaQuerySelector(selector: string): void; } ).ariaQuerySelector(selector); diff --git a/src/common/DOMWorld.ts b/src/common/DOMWorld.ts index a6d7d051..1db47d1f 100644 --- a/src/common/DOMWorld.ts +++ b/src/common/DOMWorld.ts @@ -717,52 +717,6 @@ export class DOMWorld { return elementHandle; } - async waitForXPath( - xpath: string, - options: WaitForSelectorOptions - ): Promise