mirror of
https://github.com/hanzoai/puppeteer.git
synced 2026-09-24 17:02:14 +00:00
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
1.5 KiB
1.5 KiB
sidebar_label
| sidebar_label |
|---|
| Frame.waitForSelector |
Frame.waitForSelector() method
Waits for an element matching the given selector to appear in the frame.
This method works across navigations.
Signature
class Frame {
waitForSelector<Selector extends string>(
selector: Selector,
options?: WaitForSelectorOptions,
): Promise<ElementHandle<NodeFor<Selector>> | null>;
}
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
selector |
Selector |
The selector to query and wait for. |
|
options |
(Optional) Options for customizing waiting behavior. |
Returns:
Promise<ElementHandle<NodeFor<Selector>> | null>
An element matching the given selector.
Exceptions
Throws if an element matching the given selector doesn't appear.
Example
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
const page = await browser.newPage();
let currentURL;
page
.mainFrame()
.waitForSelector('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();