Playwright · Junior · Question 58 of 75
How do you click a button inside an <iframe>?
- 1
page.getByRole('button', { frame: true }) - 2Locators reach into iframes automatically
- 3
page.frameLocator('#pay').getByRole('button')
Show the answer
Correct answer: page.frameLocator('#pay').getByRole('button')
Explanation
An iframe has its own document. frameLocator (or locator(...).contentFrame()) scopes locators to it.