Switch to v2 to see which selectors break.
Add to Chrome

Iframe practice website

Practice working inside iframes: a card form in its own frame, the way payment providers embed theirs, and a chat frame nested inside a help-center frame. Open the shop checkout

Card formUse the test card 4242 4242 4242 4242, any future expiry and any CVC.

Built well

Built to break

Nested framesA chat frame inside a help-center frame.

Built well

Built to break

Shadow root inside an iframeSwitch into the frame, then cross the root.

Built well

Built to break

Tasks: write a locator, get a grade

1Find the iframe that holds the card form (built well), the first step before any field inside it.Frames
How to locate Iframes

A frame is a separate document

An iframe holds its own document. Test tools search one document at a time, so a locator written for the page finds nothing inside the frame until you switch into it (Selenium) or scope the locator to it (Playwright’s frameLocator). The card field is visible on screen, yet findElement reports that it does not exist.

Forgetting to switch back is the next failure. After filling the card, a Selenium session is still inside the frame, so the “Place order” button on the page cannot be found until you call switchTo().defaultContent().

Finding the frame is a locator problem of its own. Switching by index, as in switchTo().frame(0), breaks as soon as another iframe is added above it: a chat widget, an ad, a consent banner. A title, a name or a test id survives. The fragile card frame has none of these, and the ids of its fields change on every release.

Frames also load on their own schedule. The frame element can exist before its document is ready, so a test that switches in and immediately looks for a field can fail intermittently. Wait for the frame, then for the field.

Nested frames need one switch per level, and parentFrame() to step back out one level at a time. The frames on this page are same-origin. Cross-origin frames add browser security limits on top of all this, and arrive in a later version of this practice site.

What a stable locator looks like

Find the frame by its title or test id, then the field by its label or test id. The well-built card frame has the title “Card details” and labelled fields. In Selenium, wait for the frame to be available and switch to it in one step, then switch back to the page before the next action outside it.

const card = page.frameLocator('iframe[title="Card details"]');
await card.getByLabel('Card number').fill('4242 4242 4242 4242');
await card.getByLabel('Expiry').fill('12/30');
await card.getByLabel('CVC').fill('123');

// Nested: one frameLocator per level
const chat = page.frameLocator('iframe[title="Help center"]')
  .frameLocator('iframe[title="Chat"]');
await chat.getByLabel('Message').fill('Hi');
await chat.getByRole('button', { name: 'Send' }).click();

In a real workflow

The shop’s checkout takes payment through this card frame. Sign in, add something to the cart, go to checkout, fill the address, enter the test card inside the frame, and place the order. Then find the new order in your order history.

COR Lens generates locators for shadow DOM, iframes and tables, and grades each one. Click the iframes above with it and compare its pick with yours.

Add to Chrome