--- sidebar_label: ElementHandle.waitForSelector --- # ElementHandle.waitForSelector() method Wait for an element matching the given selector to appear in the current element. Unlike [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md), this method does not work across navigations or if the element is detached from DOM. **Signature:** ```typescript class ElementHandle { waitForSelector( selector: Selector, options?: Exclude ): Promise> | null>; } ``` ## Parameters | Parameter | Type | Description | | --------- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------- | | selector | Selector | The selector to query and wait for. | | options | Exclude<[WaitForSelectorOptions](./puppeteer.waitforselectoroptions.md), 'root'> | (Optional) Options for customizing waiting behavior. | **Returns:** Promise<[ElementHandle](./puppeteer.elementhandle.md)<[NodeFor](./puppeteer.nodefor.md)<Selector>> \| null> An element matching the given selector. ## Exceptions Throws if an element matching the given selector doesn't appear. ## Example ```ts const puppeteer = require('puppeteer'); (async () => { 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(); })(); ```