Run the following test to click inside an iframe.
test('click inside a frame', async ({page}) => {
await page.goto('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe', {waitUntil: 'domcontentloaded'})
await page.locator('iframe[name="iframeResult"]').locator("a[title='Menu']").click()
await page.waitForTimeout(4000)
})
or
test('click inside a frame', async ({page}) => {
await page.goto('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_iframe', {waitUntil: 'domcontentloaded'})
const frame = await page.frameLocator('iframe[name="iframeResult"]')
await frame.locator("a[title='Menu']").click()
await page.waitForTimeout(4000)
})
The test errors out saying waiting for locator('iframe[name="iframeResult"]').locator('a[title=\'Menu\']')
Note: I am able to successfully locate the frame if I do
await page.locator('iframe[name="iframeResult"]').highlight()
I should have looked at it properly. There is actually an iframe inside another iframe. So, the following works.
await page
.frameLocator('iframe[name="iframeResult"]')
.frameLocator('iframe[title="W3Schools Free Online Web Tutorials"]')
.locator("a[title='Menu']")
.click()