Click in Element Inside Iframe Document Using Playwright/Python

Question:

How can I click on this element that is inside an iframe with an html document?

IMAGE

Asked By: BoTop

||

Answers:

Since Playwright version 1.17, there is a special page.frameLocator in Playwright for iFrame. This should allow you to access the elements within the iFrame without any problems.

Here is a sample code for the correct syntax:

const btn = page.frame_locator("your-iframe").locator("text=Your Text");
await btn.click();

You need now adapt the example to your HTML structure. Hope it helps you. More details for python usage: https://playwright.dev/python/docs/api/class-framelocator

Answered By: r00k13

Here’s the Python version of the sample code.

https://playwright.dev/python/docs/api/class-framelocator

locator = page.frame_locator("my-frame").locator("text=Submit")
locator.click()
Answered By: Min ho Kim

See this example that clicks on a captcha inside an iframe:

frame = page.frame_locator(Captcha_Iframe).locator(Captcha_Checkbox)
await frame.click(timeout=10000)
Answered By: IceEagle