lecture 19 of 230 completed

Frames and iframes

An iframe is a separate document inside the page. Your selectors cannot cross into it until you switch context.

What you'll learn

  • Why a correct selector can still find nothing
  • How to switch into a frame and back out
  • Where iframes actually show up in real apps

You open a payment form. The card field is right there on the screen. Every selector you try for it returns nothing. You check the spelling again and again. Teams often lose an afternoon to this.

The field was inside an iframe, and that is one of the most confusing failures in Selenium precisely because everything looks correct.

An iframe is a whole separate document embedded in the page. It has its own DOM. When you search for an element, Selenium searches the document it is currently focused on, and by default that is the main page. Elements inside a frame are invisible to that search, even though they are visible to you.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →