How to Handle iFrames in Playwright
On this page
Playwright enables us to access and interact with iframes.
Locate an iframe and its elements
To access iframe elements, locate the iframe and query the DOM elements as if you’re in the page context.
const { chromium } = require('playwright')
;(async () => {
const browser = await chromium.launch()
const context = await browser.newContext()
const page = await context.newPage()
await page.goto('https://your-page-with-an-iframe.com')
const header = await page.frameLocator('iframe').locator('h1')
console.log(await header.innerText())
await browser.close()
})()