admin管理员组

文章数量:1225070

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

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

Share Improve this question edited Feb 19, 2023 at 21:01 ggorlen 57k8 gold badges110 silver badges150 bronze badges asked Jun 26, 2020 at 13:40 ei0haroei0haro 911 gold badge1 silver badge2 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 11

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>.

You can get the ElementHandle calling $ and then call the contentFrame function:

const handle = await page.$('.frame');
const contentFrame = await handle.contentFrame();

本文标签: javascriptHow to use a selector finding an frame (iframe) using PlaywrightStack Overflow