Skip to content
CodeKruPro

frameLocator by ID

46/70

frameLocator by ID

In Playwright, use page.frameLocator(selector) to interact with elements inside iframes. Unlike Selenium, you don't "switch" context — you chain locators.

On the Frames page, the first #frame1 contains an <h1>CodeKru</h1>. The page has a second iframe with the same id (it shows CodeKru2), so page.frameLocator('#frame1') alone fails Playwright's strict mode. Add >> nth=0 to pick the first one.

Task:

  1. Navigate to https://testkru.com/Interactions/Frames
  2. Access the first #frame1 with page.frameLocator(), adding the nth part described above
  3. Find the h1 inside the frame and print its text

Expected output:

Frame content: CodeKru