Reputation: 91
I have a trivial question that I can't find an answer to using Microsoft Playwright framework. According to documentation you can fetch an iframe with the following code:
const frame = page.frame('frame-login');
But how do I use a selector to find and interact with an iframe? I need to use a CSS selector to find my iframe since it does not have an id.
Any help appreciated
Upvotes: 9
Views: 20623
Reputation: 8851
You can use elementHandle.contentFrame()
await page.waitForSelector('.class-name')
const elementHandle = await page.$('.class-name')
const frame = await elementHandle.contentFrame()
From that moment you can interact with the content of the <iframe>
like: await frame.<method_name>
.
Upvotes: 11
Reputation: 21695
You can get the ElementHandle
calling $
and then call the contentFrame function:
const handle = await page.$('.frame');
const contentFrame = await handle.contentFrame();
Upvotes: 2